ConstanObject<T> not working

Issue #66 resolved
Jan D created an issue

I created a dataprovider, which is just derived from ConstantObject (GameCurrencyConstantProvider) and represents an enum class. I used this provider as an input to another DataProvider (GameCurrencyToColorConverter), but it is not set correctly.

When i debbuged over Value of the GameCurrencyToColorConverter, i found out, that 1. Value has been called 4 times 2. argument was always first item of the enum, not the chosen one

Scene is included as an attachment.

Comments (9)

  1. Christian Oeing repo owner

    Hi Jan! I just opened the example project, but couldn't really figure out what goes wrong there. Could you tell me what happens for you and what you would expect to happen? In the example project there is no GameCurrencyConstantProvider.

    What I saw: You implement the Awake method again in your GameCurrencyToColorConverter. You should overwrite the Init method instead to do the AddBinding call(s).

    The colors are correctly changed for me, for the Enabled and Disabled button.

  2. Jan D reporter

    Hello Christian, i have applied files found on forum and it have not fixed the issue I have, but the behaviour is different. Before script applying, the color of the image is set to 0,0,0,0 (invisible). After script aplying, the color of the image does not change at all

  3. Christian Oeing repo owner

    Hi Jan! Yes, that's the expected behaviour from the files from the forum. Before the default value was set instead of waiting for the initial value. Yesterday I haven't had time to have a look at your issue, I will try to find time today. Sorry for the delay!

  4. Christian Oeing repo owner

    Okay, I found the issue: The constant provider is initialized after the converter and setter, so it doesn't provide a value yet. After it is initialized it doesn't trigger the OnValueChanged event, so the listeners are never informed about the value.

    You could add those lines to the ConstantObject.cs, then it will work:

            /// <inheritdoc />
            public override void Enable()
            {
                base.Enable();
    
                this.OnValueChanged();
            }
    
  5. Log in to comment