Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple ChangeHandlers on a LocalizedString

Discussion in 'Localization Tools' started by nicolasgramlich, Aug 13, 2020.

  1. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    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 :(

    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" :)

    Thanks,
    Nicolas
     
    Last edited: Aug 13, 2020
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
    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.
     
    nicolasgramlich likes this.
  3. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    First the Dark Theme, and then this response in the same day... :):):):):):):)

    Christmas is coming early!
     
    karl_jones likes this.
  4. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    @karl_jones
    Replaced LocalizedString RegisterChangeHandler and ClearChangeHandler with the event StringChanged


    Is this what I think it is? :eek::eek::eek:
     
    karl_jones likes this.
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
    :)
    Yes just on time!
     
  6. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Awesome! How do you feel like helping out the unity.animations team? ;) Haha j/k

    Works great so far!
     
    karl_jones likes this.
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
    Haha I help out a lot of teams :D
    Is there something in particular you need with animation?
     
    BelkinAlex likes this.
  8. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Just a teensy, tiny thing. URP support and updated samples :) 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
     
    BelkinAlex likes this.
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
    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.
     
  10. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Thanks!!! I really appreciate the follow up!
     
    cdm456852, karl_jones and thelebaron like this.