Search Unity

Bug Save during play saves random extra stuff

Discussion in 'Cinemachine' started by midsummer, Mar 30, 2021.

  1. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    Let's see if I can make any sense of this bizarre situation.


    My game has buttons that open doors. When a button is pressed, a door opens and the button is disabled for the rest of the game. Typical stuff. I just spent a few hours trying to figure out why my buttons were seemingly randomly already disabled at the start of the game...

    By chance I happened to notice that the public TriggerIsActive boolean on my button component was reset to true when I exited play mode, as expected – but a split second later something forced its state back to false, the state it had before exiting play mode. The button is a prefab, so TriggerIsActive became a prefab override every time I exited playmode.

    There's absolutely nothing in the script (or elsewhere in my project) that would cause that to happen.

    Then it occured to me that maybe, just maybe, whatever the culprit is, I should have a look at Edit / Undo right after the magic boolean corruption happens. And guess what was the last undoable action? Undo SaveDuringPlay. The only place I remembered seeing those words was the inspector of a Cinemachine Virtual Camera. So I went and unchecked Save during play on the virtual camera in my scene and now my door-opening buttons work again. Software development!

    The issue seems to affect only that one component. It's not just that one boolean field, any other public field in that class is also affected. The boolean was just the one that got toggled in-game so that I noticed.

    I don't think I imagined this because I can make it happen again just by turning Save during play back on...

    Could this just be some random GUID madness? Some bits got mangled in the importing process somehow? I have no experience of GUIDs, so I wouldn't know what to look for. Adding the button component to the scene in an otherwise empty GameObject doesn't seem to cause this to happen.


    Unity 2021.1.0f1
    Cinemachine 2.7.2 and 2.7.3 tested.
    The issue wasn't present in 2020.3. I'm not sure if the Cinemachine package got updated when I switched to 2021.1.


    Ps. I just noticed "Bugfix: SaveDuringPlay also works on prefab instances" in the changelog for Cinemachine 2.7.2. I guess Cinemachine is perhaps just not properly checking what it's saving? Is this a known issue, @Gregoryl?
     
  2. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    I just realized that the buttons do have a Cinemachine connection of sorts, it's just not very direct. The buttons were a part of a readymade set of button & door with all interaction already hooked up. A prefab consisting of two prefabs, that is. And the door does have a virtual camera inside of it, I had just forgotten about it. It's used for some optional cutscenes of doors opening elsewhere in the level.

    I had also forgotten that the Save during play setting isn't per virtual camera, it affects all of them. So when I just checked the door virtual camera, Save during play was false. It obviously was true when I experimented with the setting before. I really haven't touched any Cinemachine stuff in this project for probably a year, because it seemed to be all working fine. I guess it was just the 2.7.2 update that "broke" things with the new way it makes the save during play behaviour affect more things than just the virtual cameras. Maybe some kind of a console message about this on playmode exit would be welcome?


    EDIT:
    Oh no, it's a bit more complex than that. I just dropped an isolated button prefab with no door into the scene. Then I unpacked the prefab completely, which left nothing but regular gameobjects in the hierarchy. Cinemachine saves inspector value for even that in playmode. So it's enough that the objects are a part of a prefab in a prefab of prefabs even if they are no longer prefabs themselves in edit mode hierarchy...
     
    Last edited: Mar 30, 2021
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Thank you for reporting this bug. I could reproduce the issue! :confused:
     
    midsummer likes this.
  4. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    Great! This one was really puzzling... I’d probably still be struggling with this had I not been lucky enough to think of undo at the right time.
     
  5. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    A fix is going to be available in an upcoming patch. ;)
     
    midsummer likes this.
  6. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    Good news, I’ll check it out when it’s released.