Data loss when getter and setter are used for same context data and context is switched

Create issue
Issue #49 resolved
Christian Oeing repo owner created an issue

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)

  1. Christian Oeing 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.

  2. Christian Oeing 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.

  3. Christian Oeing 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.

  4. Log in to comment