ConstanObject<T> not working
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)
-
repo owner -
reporter - attached DataBindBugTest.zip
Sorry Christian, i uploaded wrong project before. Right one has been uploaded.
-
repo owner Okay, thanks for the update! I will have some time tomorrow and will check it out. If you have time till then, could you check if the fix for the other current issue from the forum (https://forum.unity.com/threads/released-data-bind-for-unity.298471/page-5#post-3323944) fixes your problem as well? Doesn't sound like exactly the same issue, but it was a thing deep inside the setters which might cause different problems.
-
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
-
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!
-
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(); }
-
repo owner Fixed it in repository as well, will be deployed with version 1.12
-
repo owner - changed status to resolved
-
repo owner - removed milestone
Removing milestone: 1.0.12 (automated comment)
- Log in to comment
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.