Page 1 of 1

Quest Machine not loaded when transitioning between scenes

Posted: Fri Oct 15, 2021 3:07 pm
by mightyBond
Hello!

Whenever I transition to another scene using the command SceneManager.LoadScene(), the Quest Machine Game Object is not loaded on the next scene, even though it contains the DontDestroyGameobject. How may I alleviate this problem?

I have separate Quest Machines with its own quest databases on each scene by the way.

Re: Quest Machine not loaded when transitioning between scenes

Posted: Fri Oct 15, 2021 4:14 pm
by Tony Li
Hi,

I recommend assigning all of your quest databases to the main Quest Machine GameObject that appears in the first scene. You can save this Quest Machine GameObject as a prefab variant and add it to call of your scenes. This will make it easier to save quest states across scenes.

If you don't want to do that for some reason, let's figure out which Quest Machine GameObject is being destroyed by trying these steps:
Debug steps if you don't want to use a single Quest Machine with all databases
  • Is the Quest Machine GameObject's Allow Only One Instance checkbox ticked or unticked?
  • Give each Quest Machine GameObject in each scene a unique name (e.g., "Quest Machine 1", "Quest Machine 2", etc.).
  • Then reproduce the issue. Which Quest Machine GameObject is being destroyed?
Spoiler

Re: Quest Machine not loaded when transitioning between scenes

Posted: Fri Oct 15, 2021 4:39 pm
by mightyBond
The first solution you mentioned worked! Thank you very much Tony!

Re: Quest Machine not loaded when transitioning between scenes

Posted: Fri Oct 15, 2021 5:04 pm
by mightyBond
Just a follow-up:

Quest Machine instance works well when loading another scene, but if I only just reload the same scene, the Quest Machine won't load again. Any idea how to solve this?

Re: Quest Machine not loaded when transitioning between scenes

Posted: Fri Oct 15, 2021 5:34 pm
by Tony Li
It sounds like data isn't being preserved. To change scenes in a manner that preserves save data, please replace:

Code: Select all

SceneManager.LoadScene("scene name");
with:

Code: Select all

PixelCrushers.SaveSystem.LoadScene("scene name");
Alternatives:
  • Scene Portal component attached to a GameObject with a trigger collider.
  • Add a Save System Methods component to some GameObject. Connect a UnityEvent to SaveSystemMethods.LoadScene.
  • Equivalent visual scripting methods (e.g., PlayMaker integration, etc.).

Re: Quest Machine not loaded when transitioning between scenes

Posted: Sat Oct 16, 2021 4:58 am
by mightyBond
I've changed the code, but it still has the same problems.

Whenever I restart a scene when a quest is still active, its HUD UI still persists even after reloading the scene. Afterwards, when the scene is reloaded it gives this error even though the Quest Machine Prefab has a don't destroy on load script:
Image
Image
(Note that even If i reload the scene without any quests active, it still shows the same error)

In the code changes you said earlier, do I need to add some scripts from the Save System or does it work right off the shelf?

I've also tried the 2nd alternative you mentioned but it still gives the same error.

Re: Quest Machine not loaded when transitioning between scenes

Posted: Sat Oct 16, 2021 2:30 pm
by Tony Li
Hi,

What version of Quest Machine are you using? (It's shown in the Welcome Window and in Plugins/Pixel Crushers/Quest Machine/_README.txt.)

If you play the Demo scene and load a saved game, does it work correctly in your project? Press Esc or click the Menu button to open the menu, and select Save Game to save the game. Then press Esc again and select Load Game. This will load the scene in which the game was saved (i.e., the Demo scene) and apply the saved game data.

Would it be possible for you to send a reproduction project to tony (at) pixelcrushers.com?