I have two string with the same text that I tried to add the same localization key, but it’s not working for the number 2 one. What’s the best approach to this without needing to create another localization key nor resorting to a script?
This is the debug inspector of the copied component to the second string with the same text. Where do you find this target field?
Btw:
Unity version 2021.3.15f1
Localization package version 1.3.2
Its not showing it. Its part of the Tracked Object. You may need to edit the file TrackedObject.cs and remove the HideInInspector attribute over m_Target. Check that the target is not pointing to the wrong GameObject
I only came up with this problem because I couldn’t manually set an UI text to use a table entry, but now I just figured it out!
For anyone having the same problem setting an UI text to have a localization:
Right click on right above the text field and click “Localize Property”
On the added component below, click on that dropdown. Because it doesn’t automatically show up, you have to type in the key to set it. I was having trouble because of that, but now I don’t need to copy and paste the component in the first place anymore.
The bug is still there. When do you plan to fix it?
In any case, this is my fix:
using UnityEngine;
using UnityEditor;
using UnityEngine.Localization.PropertyVariants;
public static class FixTrackedObject {
[MenuItem("Localization/Fix TrackedObject.Target")]
public static void Do()
{
foreach (var gameObject in Selection.gameObjects)
{
var localizer = gameObject.GetComponent<GameObjectLocalizer>();
foreach (var tracketObject in localizer.TrackedObjects)
{
if (tracketObject.Target is MonoBehaviour monoBehaviour) {
if (monoBehaviour.gameObject != gameObject) {
var newTarget = gameObject.GetComponent(tracketObject.Target.GetType());
if (newTarget != null)
tracketObject.Target = newTarget;
else
Debug.LogError($"Selected object doesn't have {tracketObject.Target.GetType()} component");
}
}
}
}
}
}
What bug is this? I don’t recall the one I was referring to in 2022 but it would have landed so this must be a different issue. Could you please file a bug report? https://unity.com/releases/editor/qa/bug-reporting
When I tried to apply changes on GameObjectLocalizer to the prefab, I’ve encountered the same bug. The “m_target” in the TrackedObject is set to NULL, and is serialized as “m_Target: {fileID: 0}”. Any ideas on how to fix this?
What did you try to do? Was it the same as me: copying the component to another UI text?
Because, don’t do that. Just do like I did in my reply, which is the correct way.
Right click the text mesh pro component and click Localize Property.
Right now, copying the component isn’t supposed to work because it carries the reference of the first text.
No, the bug I encountered was not when copying, but when applying changes to the prefab.
But I believe the reason is the same: the reference is incorrect. I’m just wondering what I can do to avoid the NullReferenceException, since it is a very common and reasonable operation. Can I avoid this mistake only by educating my partners? Or is there a technical solution?
As a programmer, I can understand these reasons, but the non-technical people on my team who modify prefabs most frequently might have a hard time understanding why this can’t be done.
The only thing I can think of now is for you to recreated the whole prefab, if thats ok. I’ve had problems trying to remove the localization component before.
I agree the m_target should be not hidden, or at least the component should always try to look for a localizable target if its null.
Can you show or describe what your prefab is?