Page 1 of 1
Loading from main menu re-triggering old cut scenes
Posted: Wed Jul 01, 2020 9:58 am
by rykaan
Hi Tony,
I've been looking at how cut scenes should be triggered in my game and how to prevent them re-triggering etc. I have an OnStart trigger when loading into a particular scene that plays a cut scene if a variable is false, and then at the end of the cut scene I set it to true so it doesn't re-trigger, simple stuff. The problem I'm having is that if I load into that scene from my main menu instead of loading from within the game world, the cut scene will re-trigger. This is despite the cut scene having the 'wait one frame' before triggering, which I would expect would be enough time to notice the variable is set to true as it was completed then saved previously.
After triggering the scene the first time and saving:
Moving from another scene into the affected scene doesn't trigger it.
Loading the game while in the scene doesn't trigger it.
Loading the game from the main menu into the scene DOES trigger it.
If I load the game from the main menu in a different scene then move into the affected scene it also doesn't trigger.
I'm using the same 'SaveSystemMethods.LoadFromSlot' method to load in both cases. The only difference I can see is that the main menu doesn't already have the loaded games dialogue manager status at the point when the game is loaded.
Any idea what's going on and how I can sort it out?
Cheers,
Rob
Re: Loading from main menu re-triggering old cut scenes
Posted: Wed Jul 01, 2020 1:23 pm
by Tony Li
Hi Rob,
Have you added a DialogueSystemSaver component to the Dialogue Manager GameObject? This should make sure that the Dialogue System's state (variables, quests, etc.) are restored before any OnStart triggers run.
Re: Loading from main menu re-triggering old cut scenes
Posted: Thu Jul 02, 2020 8:07 am
by rykaan
Hi Tony,
Yeah I have one attached, that's how the game loads correctly from any other scene. But specifically from the main menu into a scene with a cut scene trigger causes the cut scene to play again. I do have a Dialogue Manager in the main menu scene that doesn't have any data loaded in it. Then when the game loads in it is updated with the save slot data. Is the cutscene somehow triggering off the blank Dialogue Manager being brought in from the main menu somehow? I assumed it would be updated before that could happen. I have 'Allow only one instance', 'Don't Destroy on load' and 'Preload resources' selected in the settings if that helps.
Cheers,
Rob
Re: Loading from main menu re-triggering old cut scenes
Posted: Thu Jul 02, 2020 9:03 am
by Tony Li
Hi Rob,
Yes. At runtime, the Dialogue Manager from the main menu scene survives scene changes and replaces any Dialogue Managers in subsequent scenes. Can you set up the Dialogue Manager in the main menu scene with the same components as the one in your gameplay scene? Typically, you'll set it up once -- for example, in a gameplay scene for easy playtesting directly from that scene -- and save it as a prefab variant. Then put that same prefab variant in the other scenes, including the main menu.
Re: Loading from main menu re-triggering old cut scenes
Posted: Thu Jul 02, 2020 11:16 am
by rykaan
Hi Tony,
I have exactly that. The same Dialogue Manager variant in the main menu. But when the game first launches it's in a blank state, since no game save slot has been loaded yet. Then that blank version triggers the cutscene before the dialogue manager has the correct save data.
I'm also looking into how to wipe that prefab clean so that starting a new game after quitting to the main menu doesn't have residual data from the previous save. After sorting the first issue anyway.
Re: Loading from main menu re-triggering old cut scenes
Posted: Thu Jul 02, 2020 1:24 pm
by Tony Li
Hi Rob,
I forgot to mention before that the Dialogue System Trigger's 'wait one frame' only waits one frame to start the sequence (to give GameObjects that the sequence will manipulate time to initialize themselves). It doesn't wait one frame before checking the Dialogue System Trigger's Conditions.
Please try this:
1. Change the Dialogue System Trigger to OnUse.
2. Add a Timed Event component to the Dialogue System Trigger's GameObject. Select Frames > 2.
3. Configure OnTimeReached() to call the Dialogue System Trigger's OnUse method.
This is mostly just an information-gathering step. But it should also get you up and running in the meantime, too.
Please also temporarily tick the Debug checkboxes on the Save System component and the saved game data storer (e.g., PlayerPrefsSavedGameDataStorer). This will log save system activity. You might see some issue in the order that things are running. Normally, it should run like this:
1. Save system retrieves saved game data, including what scene to load (unless you've unticked Save Current Scene).
2. Save system tells the scene transition manager (if present) to play the 'leave scene' transition. Then it loads the scene where you saved the game.
3. When the scene is loaded, it tells all savers in the scene that now is the time to retrieve their data on scene load. Most savers do
not do anything at this point, but the DialogueSystemSaver does. It retrieves its data from the save system. This is precisely so Dialogue System Triggers that run OnStart have the correct data available to them.
4. After that, the scene's GameObjects run their Start methods, and simultaneously the save system tells the scene transition manager (if present) to play the 'enter scene' transition.
5. After a number of frames specified on the Save System component (usually 1), the save system tells all savers in the scene to do their regular ApplyData() method (i.e., restore their states from save data).
Final note: Call
SaveSystem.RestartGame() to wipe whatever save data is in memory and start fresh.
If that doesn't help, please feel free to post screenshots or email a reproduction project to tony (at) pixelcrushers.com. I'll be happy to take a look.
Re: Loading from main menu re-triggering old cut scenes
Posted: Mon Jul 06, 2020 5:19 am
by rykaan
That worked like a charm Tony, thanks a bunch. The RestartGame method was also exactly what I was looking for. I was clearing the save data, but didn't know how to wipe the Dialogue Manager when starting a new game, and this does both.
Cheers again,
Rob
Re: Loading from main menu re-triggering old cut scenes
Posted: Mon Jul 06, 2020 7:40 am
by Tony Li
Great! Glad to help.