Forum rules - please read before posting.

Need Help with 'Remember Animator' and Loading

Please help me understand the concept of using a Remember Animator component after a game Load.

I have a Sprites Unity animation of a picture hanging on a wall. It has 3 different clips:
1. Picture_UP (picture hanging on the wall); Layer Default State
2. Picture_FALLING (the picture falls to the ground)
3. Picture_DOWN (picture is on the ground)

If I trigger my hotspot, the actionlist plays the clips sequentially and the picture falls off the wall and onto the ground. Perfect. If I exit the scene then enter it again the Remember Animator works (the picture remains on the ground where it was when I left the scene).

However, if I Save, Quit, and then Load the game, the picture appears as on the wall (the Layer Default State) after the scene is loaded.

Why doesn't the Remember Animator work on the Load?

The only solution I've been able to devise is record a global string variable "PictureLocation' and set it to "down" at the end of the actionlist. Then I use an On Load cutscene and check the variable. If it's "down" then it triggers an Object:Animate:Clip="Picture_Down". This method is becoming increasingly tedious as more of my animations have several clips.

Is there a better way to approach this?

Comments

  • All Remember components should restore their data both when switching scene, and when loading a save - the state of the picture should be the same in both cases.

    How about if you trigger the Hotspot, save the game in another scene, restart, load, and then enter the scene with the picture?

    The RememberAnimator was devised to avoid the need for the "check variable on load" process that was previously necessary.  It works by recording three things:

    1) The parameter values
    2) The layer weights
    3) The currently-playing animation clip

    There's not enough detail here for me to say why it wouldn't work on the Load.  We'll need to do some debugging to try to find out what's going on.  Open up RememberAnimator.cs, find the LoadData function, and place the following after the first line:

    if (data == null) Debug.Log ("No data for RA " + name); else Debug.Log ("SavePrevented = " + SavePrevented + ", data.savePrevented: " + data.savePrevented + ", data.parameterData: " + data.parameterData + ", data.layerWeightData " + data.layerWeightData + ", data.stateData: " + data.stateData);

    (i.e. just below "AnimatorData data = "...)

    That should display a message in the Console when its data is retrieved.  Let me know the full message both when loading succesfully (from another scene), and unsuccesfully (from a save file).
  • Thanks. I added the lines of code and here's what I copied from the Console:


    1)  When I Exit the scene and return (picture is down where it should be):
    SavePrevented = False, data.savePrevented: False, data.parameterData: , data.layerWeightData , data.stateData: -1917115422,1|
    UnityEngine.Debug:Log(Object)
    AC.RememberAnimator:LoadData(String) (at Assets/AdventureCreator/Scripts/Save system/RememberAnimator.cs:58)
    AC.ConstantID:LoadData(String, Boolean) (at Assets/AdventureCreator/Scripts/Save system/ConstantID.cs:74)
    AC.LevelStorage:SendDataToScene(SingleLevelData, Boolean, SubScene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:140)
    AC.LevelStorage:ReturnCurrentLevelData(Boolean) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:77)
    AC.SceneSettings:OnStart() (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:129)
    AC.MultiSceneChecker:Start() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:72)

    2) When I Load the scene from within the game (picture is back on the wall):
    SavePrevented = False, data.savePrevented: False, data.parameterData: , data.layerWeightData , data.stateData: 1298138828,0|
    UnityEngine.Debug:Log(Object)
    AC.RememberAnimator:LoadData(String) (at Assets/AdventureCreator/Scripts/Save system/RememberAnimator.cs:58)
    AC.ConstantID:LoadData(String, Boolean) (at Assets/AdventureCreator/Scripts/Save system/ConstantID.cs:74)
    AC.LevelStorage:SendDataToScene(SingleLevelData, Boolean, SubScene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:140)
    AC.LevelStorage:ReturnCurrentLevelData(Boolean) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:77)
    AC.SaveSystem:_OnLevelWasLoaded() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:583)
    AC.SaveSystem:ReceiveDataToLoad(SaveFile, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:485)
    AC.SaveFileHandler_SystemFile:Load(SaveFile, Boolean) (at Assets/AdventureCreator/Scripts/Save system/FileHandling/SaveFileHandler_SystemFile.cs:125)
    AC.SaveSystem:LoadSaveGame(SaveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:415)
    AC.SaveSystem:LoadGame(Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:340)
    AC.MenuSavesList:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSavesList.cs:711)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2286)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1932)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2026)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:300)



    So to be more clear, I'm performing an Autosave on the OnStart Cutscene of both scenes ("Office" and "Tall Cabinet").

    When I Load the Autosave from within the scene "Tall Cabinet" (which has the picture), the Animator gets reset to the Default Clip.

    When I Load the Autosave from the other scene "Office" and then navigate to "Tall Cabinet", the Animator displays the correct clip.

    If you need me to PM you the package from this test I can do that. It's only 522KB.
  • From what I can tell, the Remember component is loading correctly - it's that the "saved" state is wrong.

    I can't tell from this if this is down to AC, or user error.  Send away, but let me know your Unity/AC version numbers as well.
  • Thanks. I've sent the file via PM

  • Seeing this for myself, the RememberAnimator is doing its job correctly - it saves when the Autosaving / exiting the scene, and loads when loading / entering the scene.

    The issue is that the Animator itself does not have time to update itself in between the load and the save.  When the scene loads, the RememberAnimator loads back the data and applies it to the Animator.  In that same frame, the Autosave is requested, and the RememberAnimator saves the state of the Animator - but the Animator has not yet updated to its previous state.

    This occurs in the same frame because you are Autosaving with the Save: Save or load Action as the first Action in your OnStart Cutscene.

    This should already be fixed in the latest release, v1.65.2.  You can also remedy it by inserting a brief delay with an Engine: Wait Action, or removing the "save" Action and checking Autosave after? in the ActionList's properties.
  • The first action in the OnStart cutscene is an AutoSave, but there's no loading action in the OnStart cutscene. The Scene Switch actions retain the proper Animator clip, but when the game is loaded from a saved game, the Animator clip resets to the Default state.

    For the Autosave to happen immediately after the game is loaded as you mentioned above, wouldn't the OnStart cutscene need to be triggered after the saved game is loaded? 
  • The loading is automatic - and occurs after any scene change.  The OnStart cutscene does trigger after the load.
  • It's working now, thank you!

    The solution that worked for me:  I deleted the Autosave action that I had created as the first action of the OnStart Cutscene and then ticked the "Autosave after?" box at the top of the Inspector.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.