Page 1 of 2

BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 12:41 pm
by putte954
Hi Pixel Crushers,
I love your system so far. I have however one issue with the following code (snippet)

Code: Select all

            
            SaveSystem.BeforeSceneChange();
            SaveSystem.LoadFromSlot(selectedSlot);
It loads the scene correctly. But the objects that have an IncrementOnDestroy attached still trigger.

Please help. It has been driving me up the wall!
Thank you very much in advance

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 12:56 pm
by Tony Li
Hi,

Are you sure SaveSystem.BeforeSceneChange() is being called? Are the Increment On Destroy components in the active scene(s) at the time that it's called?

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:12 pm
by putte954
Hi Tony,
Thank you for the quick reply!
* Yes I am absolutely positive that they are called. The code snippet in the Forum post is a direct copy from my source code.
* Yes, my project has only one scene and it basically loads itself again.

I've been stepping through the code BeforeSceneChange() seems to iterate over m_savers.Count
Which includes all the on On Destroy components in the active scene(s) and calling the saver.OnBeforeSceneChange()

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:19 pm
by putte954
Hi Again,
Just to add. It seems to only Trigger the On Destroy component(s) for the objects that were disabled by 'picking them up'

Problem example:
1) Start a new game
2) Pick up a coin.
3) On Destroy objects gets triggered => coin count goes up to 1.
4) Save game in slot 1.
5) Restart Game => Coin count goes to 0 as expected.
6) Load game from slot 1
7) Coin message is shown and coin count goes to 2 (instead of the correct coin count of 1)

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:29 pm
by Tony Li
Does your scene have a Dialogue System Saver component? It's typically placed on the Dialogue Manager GameObject. Certain Dialogue System components such as Increment On Destroy rely on the Dialogue System Saver to pass them BeforeSceneChange events.

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:36 pm
by putte954
Yes, I placed it on the dialogue manager wiht the standard settings:
Key: empty
Append Saver Type To Key: Not ticked.
Save Accross Scene changes: Ticked
Restore State on Start: Not Ticked
Skip Apply: Ticked
Save Raw Data: Not ticked

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:42 pm
by Tony Li
Would it be possible for you to send a reproduction project to tony (at) pixelcrushers.com?

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:46 pm
by putte954
When I disable the Dialog System Saver All "On Destroy" items seem to be triggered when loading the slot.
When I enable the Dialog System Saver only the "On Destroy" the items that are disabled due to the loading are triggered.

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:50 pm
by putte954
The problem is, it's 2.6Giga bytes big..
I'm a bit of a Unity Noob so I don't know how to boil that down to only the files you need?

Re: BeforeSceneChange and LoadFromSlot problems

Posted: Thu Mar 18, 2021 1:56 pm
by Tony Li
It's fine to send a 2.6 GB project. The reproduction project link above explains which files you can zip up and which you can omit.

I can try to reproduce it here later today first if you'd prefer.