Forum rules - please read before posting.

Load and Save during Timelines issues

edited April 2020 in Technical Q&A

Hi Chris,

Recently, I've started learning Save/Load system but I have some issues. The main things is about Timelines. I have a lot of Timelines with objects animations, player animations, canvas, sounds, speeches, lights etc. so - basically a lot of things used. It is very important to store information from Timelines as well as choose when I don't need to store information. I have Remember Timeline scrip assigned to every Timeline (did this with Auto-add Save component button) but something is not working properly. Here are several examples of what I mean and where I have issues:

1. Lights
I have Timeline with spotlight that changes color from red to blue and intensity from 1 to 2. But after I load my game everything stay at last state but not goes back to original. I need all lights in Timeline remember their original states.

2. Particles
Same for particles - I have animation of particle effect that changes transparency and amount of particles but after I load my game everything stay at last state but not goes back to original.

3. Canvas
I have Timelines with black canvas inside with transparency Fade In/Out. I use them to blend my game with other cutscenes that were also made with help of Timeline. But, when I try to load my game let say during Fade Out animation (at that moment when canvas is still black), Timeline basically freeze this moment, and when the game is starts, that black canvas overlaps the screen and I can't see anything but the game is running. So, in this case, I need somehow to skip Timelines with black Fade In/Out canvas when I parallel load the game.

Same goes for all other type of assets that are placed in timeline, again, it could be everything - starting from a simple mesh, groups, light and ending with particles, post-precessing volumes, lights etc.. I am not sure how to make everything work with Save and Load system. I've watched Manual as well as your tutorials on YouTube but have not found how to deal with Timelines. Please help. I

AC 1.70.2
Unity 2018.1.of2

Comments

  • So far as using a black canvas goes, be aware that v1.70.0 introduced the "Camera Fade" track type, which allows you to fade in/out the AC MainCamera in Timeline.

    It sounds like many of these issues are connected, so let's start with your first (Lights) and take things from there.

    When exactly are you saving, and when are you loading to? Before/after a Timeline, or while one is playing? As with Cutscenes in general, I do recommend that you limit the ability to save to regular gameplay.

    The Remember Timeline component should save and restore both it's Play state (i.e. whether it's playing or not), and the point at which it's currently at (i.e. the frame number). How this effects other objects that the Timeline itself controls is down to Unity.

    Is the state of the Timeline at least being correctly restored, and what is it being restored to?

    Please elaborate with just your Lights issue for now. So the lights are red by default (i.e. not affected by the Timeline), and the Timeline (non-looping) changes it to blue, correct? At what points are you saving/loading, what is the state of the Timeline when loading, and what is the Playable Director component's Wrap Mode set to?

  • edited April 2020

    Yes, I believe that I am doing something wrong, I agree - it is one problem that have the same roots. Let's go step by step and check example with the light source. I did video for you to make sure that you see how everything is working. Here is the link to your Dropbox folder on my PC:

    https://www.dropbox.com/sh/6mr8z7qp88mg6qw/AAD1Rv-UbtfaV0o6COhmbFqua?dl=0

    In words - I did a simple test animation with light source with red color and intensity 1. In animation, I change color from red to blue and intensity from 1 to 5. Wrap Mode set to None by default. I also have Remember Timeline script with Save bindings and Save Timeline assets unchecked by default.

    First, I save my game before I play Timeline. Next, I play animation from ActionList - Engine: Control Timeline, so my light become blue and intensity become 5. And right after this, I am loading my game and expect to see that light has red color and intensity is 1, as it was at the beginning, but they are not - light stays blue and intensity stays 5. Same issue went when I save game during the Timeline.

    "Is the state of the Timeline at least being correctly restored, and what is it being restored to?" - sorry, not sure how to check this, again maybe I am did everything just in half of what it should be.

    As for Fade In and Out feature in v1.70.0 -is good news but in my case it's not just about Fade, cos I have canvas with images that appears in the middle of a Timeline, so basically I am using canvas in different ways, not just for Fades.

  • edited April 2020

    Thanks for the video, that helped me recreated the issue.

    The nature of the problem is partly down to AC, but also partly down to Unity (or at least the way it behaves).

    When I asked about the state of the Timeline, I was referring to the Current Time field in the Playable Director's Inspector - which determines how "far along" the Timeline's playback is. This value should be stored and restored by the Remember Timeline component, though the issue itself can be broken down into two:

    1) If the Timeline is not supposed to be saved, the "effects" of this time value are not felt. This is an AC issue, and can be addressed by opening up RememberTimeline.cs, finding the instance of:

    director.Stop ();
    

    And inserting the following just after it:

    director.Evaluate ();
    

    2) If the Playable Director's Wrap Mode is set to None, then - upon completion - the Current Time will revert back to 0, though the effects of it won't be. I'm not sure if this classifies as a bug, but I don't feel it's too intuitive. Either way, because the time reverts back to 0, this is what AC will save/load. Therefore, if you want the effects of playing the Timeline to be felt after it's finished playing, you'll need to set the Wrap Mode to Hold.

  • I've tried to recreate what you suggested but both are not working. Again, maybe I did something wrong, so please check another video.

    https://www.dropbox.com/sh/6mr8z7qp88mg6qw/AAD1Rv-UbtfaV0o6COhmbFqua?dl=0

  • I suspect what you're seeing are other Timelines.

    Basically, the code change forced Timelines to run their saved frame if not being played. This is because without doing so, changing a stopped Timeline's position will have no effect on the animation itself. This is a design choice / behaviour on Unity's part, so really this is me just looking for a workaround.

    You should be able to confirm this by running the same test in a new scene, i.e. without any other Timelines to interfere with things.

    Unity's own advice on this issue is to rely on separate Animators or scripts to manually revert the state of Timeline-controlled things (e.g. the light intensity / colour) separately - which isn't that great a solution IMO.

    I'll have a think about this further, but the next step would be to make the "Evaulate" call optional, so that it's at least the designer's choice.

  • Yes, you are right- it shows me another timeline but not exactly how it should be. Telling the truth, I am not familiar with all these Unity "things" that you are describing, obviously, you are the great master and I am nervously smoking near with you....ahahah! My strongest part is art but definitely not AC and even not Unity:)

    I will be really glad if you can help to find a solution as soon as it is possible, cos otherwise, all I have done in Utopia will be in vain, cos most part of this game based on cutscenes and animations that were done with Timelines. Actually, I was about to publish the demo this week at Steam but found this issue and was really upset that now I have to postpone the release. So, ye, will be really glad if you can help with this to find the best and simple solution.

    I'll try to repeat this test in an empty scene and will share with you result.

  • edited April 2020

    Ok, I did a test and it's working now! Please, take a look at new video, same link:)
    Now, what is next step, how to make work with all other Timelines?

  • Your work certainly won't have been in vain - though we might need a bit more work to get things exactly right.

    To try to explain the situation a bit better: a Timeline only makes changes to its various GameObjects if it's actually allowed to play - even if it's just for a single frame. The reason your "save 1" in the new video now works is because it's forcing the Timeline to replay the first frame - and then stop.

    Again, this is really more of a case of dealing with the Timeline's behaviour - and not an issue with AC specifically.

    This code change - i.e. the call to "Evaluate" - may not always be something you want to do. If you were happy with the way other Timelines were playing, then there's no need to call Evaluate on those Timelines. I shall PM you a small package that makes this call a configurable option in the Inspector.

    Next, lets try moving your Timeline tracks forward one frame - so that they don't appear when Timeline evaluates the first frame.

    As a test, bring back one more Timeline into your test scene - the one from the previous video, with the full-screen overlay.

    With that, keep the Evaluate function call - but move the tracks forward a frame so that the first frame itself shows no overlay. I'm hoping that with that, you shouldn't get the overlay when you save/load in the same way as before.

  • Got an error:
    Assets/AdventureCreator/Scripts/Save system/RememberTimeline.cs(136,47): error CS1501: No overload for method GetComponent' takes3' arguments

  • Apologies - the code I sent partially refers to some changes made to AC elsewhere.

    Open up RememberTimeline and replace line 136 with:

    ConstantID savedObject = Serializer.returnComponent <ConstantID> (bindingID, gameObject);
    
  • edited April 2020

    Got it, I've replaced this line and now it doesn't give me that error. But I now save system is not working again. I did a step by step tests in another video, please take a look at this 2020.04.10_TimelineSaveIssue, same link at my Dropbox.

  • edited April 2020

    The package I sent you merely makes the "Evaluate" call optional - and this won't be enabled by default. To have your test with the lights working again, you need to expand the Remember Timeline's Inspector and check the new Evaluate when stopped? option that the package provides.

    Disabling your Timelines and deleting them should have no difference, as will deleting other GameObjects that your test Timeline does not control.

    Going back to my post on the 9th, have just your light Timeline, and the "black screen" Timeline active. In both Inspectors, check Evaluate when stopped?.

    In the case of the "black screen" Timeline, the problem will return for that - so try my advice of moving everything forward a frame to see if that resolves it.

    Be aware, though, that this is not a catch-all "fix" - just a tool in your box to help solve these issues. You will need to decide which Timelines have/need to have this option checked, but for now let's just see the results of having just those two together.

  • edited April 2020

    Hey Chris, I did what you said and first I thought it was working, but then I've started moving forward trying to see how this works with other timelines but found that saving issue is happening not only with timelines but with ActionLists that have parameters (maybe I am wrong, I can't understand where to search).

    I did another video for you. This time I've shared some part of my game in details, showing everything step-by-step. Please, take a look on this video, same folder - 2020.04.15_TimelineSaveIssue

  • I can't hear you well once the game begins - if you need to take any more videos, please run the game muted and in the Editor so things are more clear.

    In the case of your lights, you're sending "TurnOn" and "TurnOff" messages to them - is that because you've attached the LightSwitch component?

    I expect that the issue isn't related to parameters - if you were to control e.g. the lights directly in the original Cutscene, you'd get the same thing. When you save the game after the Cutscene, the change has been made already - how it was done is irrelevant.

    As with all scene objects, AC can only save data that has been flagged for saving with an appropriate Remember component. See the Manual's "Saving scene objects" chapter if you need full details. There is no "Remember Light" component in AC's official package, but here's one for you:

    using UnityEngine;
    
    namespace AC
    {
    
        [RequireComponent (typeof (Light))]
        public class RememberLight : Remember
        {
    
            public override string SaveData ()
            {
                LightData lightData = new LightData ();
                lightData.isOn = GetComponent <Light>().enabled;
                lightData.objectID = constantID;
    
                return Serializer.SaveScriptData <LightData> (lightData);
            }
    
            public override void LoadData (string stringData)
            {
                LightData data = Serializer.LoadScriptData <LightData> (stringData);
                if (data == null) return;
                GetComponent <Light>().enabled = data.isOn;
            }
    
        }
    
        [System.Serializable]
        public class LightData : RememberData
        {
    
            public bool isOn;
            public LightData () { }
    
        }
    
    }
    

    This is taken from the Saving custom scene data tutorial, which explains how to create custom Remember scripts.

    Be careful about disabling/enabling entire GameObjects, as it's not possible for Remember components attached to them to load properly once disabled.

    However, a more general approach to saving basic object states is to rely on animation. In the case of a light, for example, you could instead use an Animator to control its state (two simple On/Off states with a bool parameter), and then control that animation playback with the Object: Animate Action.

    What you can then do is save this Animator's state using the Remember Animator component - as this will save both its current state and all parameter values. So rather than saving the light's state itself (with Remember Light), you can instead just save the animation that controls it.

    This technique can work for anything you control via animation - i.e. enabling/disabling a GameObject, it's position, etc.

    Finally, you can also consider saving such states in Timelines as well, since the Activation track can be used to enable/disable GameObjects. When used with a RememberTimeline component (and the Evaluate technique above) you can save it's state that way.

  • Sorry Chris, I've noticed that sound was very loud after I send you this video. Anyway, thank you for all your help and all suggestions, I'll look at all this and will find the best solution for my game or will write you again...ahahaha!

    Thank you and stay safe!

  • Will you update Remember Timeline script and evaluate function in the next update?

  • In the same way I've updated it in the package I sent you, yes.

  • Super! Thank you!

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.