Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Inconsistent behaviour with Arguments and Add

Discussion in 'Localization Tools' started by Hellfim, Nov 3, 2023.

  1. Hellfim

    Hellfim

    Joined:
    Sep 11, 2014
    Posts:
    123
    Hi! I'm getting to know Unity's localization solution. So far so good, but I believe I've met a bug/strange behaviour.
    Suppose I have following methods
    Code (CSharp):
    1.  
    2. private LocalizedString LocalizedString;
    3.  
    4. private void SetupWithArguments(IProperty<Int32> property)
    5. {
    6.     var localizationVariable = new IntVariable();
    7.     property.ValueChanged += updatedValue =>
    8.     {
    9.         localizationVariable.Value = updatedValue;
    10.         LocalizedString.RefreshString();
    11.     };
    12.     LocalizedString.Arguments.Add(localizationVariable);
    13. }
    14.      
    15. private void SetupWithAdd(IProperty<Int32> property)
    16. {
    17.     var localizationVariable = new IntVariable();
    18.     property.ValueChanged += updatedValue =>
    19.     {
    20.         localizationVariable.Value = updatedValue;
    21.     };
    22.     LocalizedString.Add("0", localizationVariable);
    23. }
    24.  
    No, I don't really understand why do I have to manually invoke RefreshString when I'm adding localizationVariable via Arguments, while adding it using LocalizedString's Add method updates string automatically when changed.

    Is it an intented behaviour or bug?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,149
    Hi,

    Arguments are just a list of objects that are used in a similar manner to string.Format, they are addressed via their index and can be any type of object.
    Whilst you can add persistent variables to Arguments (you can add anything) it's not advisable and you will likely encounter issues.
    The correct way to work with IVariables is through the IDictionary<string, IVariable> methods that LocalizedString has.
    Think of Arguments as something used when you are not using persistent variables. I.E you just want to add a primitive.
     
    Hellfim likes this.