BUG: Local params are ignored if parent disabled

2 years 1 month ago #2957 by jeek313

I believe I have found a bug in the latest release of I2 Localization.

As of version 2.8.5f1, the LocalizationParamsManager is ignored if its parent gameobject is currently not active in the hierarchy.

For example, let's say I have a game window containing a term that translates to "{[WINNER]} is the first of {[NUM_PLAYERS]} players." Before displaying (enabling) the window, the following method is executed:
private LocalizationParamsManager paramsManager;

private void InitializeWindow() 
    paramsManager.SetParameterValue("WINNER", "Frank");
    paramsManager.SetParameterValue("NUM_PLAYERS", "3");

In previous releases, the text would (correctly) show up in-game as "Frank is the first of 3 players." However, in the latest release, it will show up as "{[WINNER]} is the first of {[NUM_PLAYERS]} players."

While debugging this issue, I have found the exact line of code where this is caused. It is located in LocalizationManager_Parameters.cs at line 115:
internal static string GetLocalizationParam(string ParamName, GameObject root)
    string result = null;
    if (root)
        var components = root.GetComponents<MonoBehaviour>();
        for (int i = 0, imax = components.Length; i < imax; ++i)
            var manager = components[i] as ILocalizationParamsManager;
            if (manager != null && components[i].isActiveAndEnabled) // <- right here
                result = manager.GetParameterValue(ParamName);
                if (result != null)
                    return result;

This method checks the LocalizationParamsManager component's isActiveAndEnabled property. (This check was not present in previous releases.) At the time of calling the SetParameterValue() method (which leads to calling LocalizationManager.GetLocalizationParam()), my window is still disabled and therefore isActiveAndEnabled returns false.

The presumably wanted behavior is to check whether the component itself is enabled, rather than active and enabled.

Therefore, my proposed solution is to replace the condition

Please Log in or Create an account to join the conversation.

2 years 1 month ago #2960 by Frank
The check to see if the component is active was introduced to allow having a Localize component use more several ParamManagers and switch between them by enabling them (at the component or the gameobject level).
But as you point out, that same can be accomplish by testing just the component, that way your case and similars will work.

I will modify the code to handle this.

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out

Please Log in or Create an account to join the conversation.

Time to create page: 0.156 seconds
Template by JoomlaShine