- marked as critical
Data loss when getter and setter are used for same context data and context is switched
My scenario is this: I have a couple of Unity UI sliders that I want to control values with for a given game object that the user has selected. Kind of like having one set of sliders to control happiness and age for characters, one at a time, based on what character is selected by the user. I have set up the sliders to read and write data from/to a Context on a ContextHolder on the canvas. When the user selects a character I set the Context on the ContextHolder to one stored on that character, to let the user control and see the same type of values for that character instead. You can set the sliders and the values in the current context update as expected, and if updating the values of the context manually in the inspector for the ContextHolder the sliders move accordingly. However each time I swap Context on the ContextHolder the values in the previous context get reset so that when I switch back later all sliders are are at 0.
It is not clearly defined how the data flow works when the context is swapped. Right now it leads to a data loss which is not acceptable.
Comments (10)
-
reporter -
reporter I setup a small example (TwoWayBindings) to reproduce the case, but couldn't completely. There way a bug though that reset the context data when the slider was inactive at first and got enabled. That one was fixed, but it had nothing to do with the context switching which worked correctly.
For now I'll close this bug. If it should reoccur in version 1.0.10 (released in a few weeks), I will reopen the bug.
-
reporter - changed status to resolved
-
reporter - changed status to invalid
-
I still get the issue, perhaps I could share with you a small test project? Click a button to select a context, set the slider and then click another button. Every click will reset the slider data for the current context, when swapping to another context.
https://www.dropbox.com/s/aq69ugbdubxxf1l/DataBindingTests.zip?dl=0
-
reporter - changed status to open
Okay, thanks for the example project. When I tested it I couldn't reproduce it, so I closed the bug for the moment. I will try it out tomorrow.
-
Ok thanks, here is a video showing how to reproduce it: I want the slider to remember what I set it to for both contexts.
https://www.dropbox.com/s/pgzlbxlfmyt0tau/DataBinding.mov?dl=0
-
reporter Thanks a lot for the example, Alvar. In my previous test I haven't replaced the whole context on the context holder, but only changed the context in a parent context, which worked.
With your example I was able to reproduce the issue. The reason for the bug are the data updates on a context changed of the context holder. The first context change triggers a chain of changes which will update the slider value. Due to this slider value change a callback is triggered on a behaviour that still works with the old context, so the wrong context data is set to the slider value.
For now I delayed the data update after a context change to the end of the frame, so other behaviours have the chance to update their contexts as well. That solves your use case.
I'm not 100% content with the solution, but it was the one with the smallest required changes. Maybe I will tackle those issues with a later refactoring, right now I'm a bit short on time.
-
reporter - changed status to resolved
Resolved in v1.0.11
-
reporter - removed milestone
Removing milestone: 1.0.10 (automated comment)
- Log in to comment