Inconsistent behaviour with Arguments and Add

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

private LocalizedString LocalizedString;

private void SetupWithArguments(IProperty<Int32> property)
{
    var localizationVariable = new IntVariable();
    property.ValueChanged += updatedValue =>
    {
        localizationVariable.Value = updatedValue;
        LocalizedString.RefreshString();
    };
    LocalizedString.Arguments.Add(localizationVariable);
}
     
private void SetupWithAdd(IProperty<Int32> property)
{
    var localizationVariable = new IntVariable();
    property.ValueChanged += updatedValue =>
    {
        localizationVariable.Value = updatedValue;
    };
    LocalizedString.Add("0", localizationVariable);
}

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?

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.

1 Like