Multiple ChangeHandlers on a LocalizedString

Hey everyone,

first of all, terrific package so far!

I have one remaining issue before I can wrap up localization in my game.

  1. I have units in my game that have names.
  2. I have a Unit ScriptableObject that used to have just a string (“Knight”) but now it’s a LocalizedString. No problem so far.
  3. Everything is fine as long as the LocalizedStrings are used only “once at a time”.
  4. The issue is when the string shows up multiple times at once. Say I have a list of units that have the name of the unit (see screenshot below), some of them are pointing to the same “Knight” LocalizedString, things start to break (as in not all Texts update) because LocalizedString only has a single ChangeHandler.

It expresses itself like this usually:

… where only one of them (the last one) gets the changehandler callback called, because RegisterChangeHandler is not a list, but gets cleared as soon as you call RegisterChangeHandler again.

What’s the proposed pattern to have all of them resolve/update when the local is switched?

I guess I could fire off one public AsyncOperationHandle<string> GetLocalizedString(params object[ ] arguments) per text? The downside is that it wouldn’t automatically update when the locale is changed, which is what makes the ChangeHandler stuff so very useful :frowning:

Bonus question:
Why is the ChangeHandler not a “List” and instead just a single reference that gets overwritten? Feels like a very useful thing to have it be able to “multiplex” :slight_smile:

Thanks,
Nicolas

Hi,

Good question. At the time it was envisioned that it would be a LocalizedString with a single target however your use case makes a good argument for having multiple subscribers. I’ll see if we can convert this into an event in time for the next release.

1 Like

First the Dark Theme, and then this response in the same day… :):):):):):):slight_smile:

Christmas is coming early!

1 Like

@karl_jones Replaced LocalizedString RegisterChangeHandler and ClearChangeHandler with the event StringChanged

Is this what I think it is? :hushed::hushed::hushed:

1 Like

:slight_smile:
Yes just on time!

Awesome! How do you feel like helping out the unity.animations team? :wink: Haha j/k

Works great so far!

1 Like

Haha I help out a lot of teams :smile:
Is there something in particular you need with animation?

1 Like

Just a teensy, tiny thing. URP support and updated samples :slight_smile: It’s been >6 months since we’ve been “promised” URP support and the samples haven’t been updated ever since. We all understand that things tend to take longer than anticipated, but the lack of updates around this package is somewhat saddening.

https://github.com/Unity-Technologies/Unity.Animation.Samples/issues/1#issuecomment-584739445

1 Like

I spoke to the team. They had put some of the sample development on hold due to code churn. Now that some pieces have landed they can resume updating the samples and expect to be able to deliver an updated version towards the end of September.

8 Likes

Thanks!!! I really appreciate the follow up!

3 Likes