Quest Machine not loaded when transitioning between scenes

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mightyBond
Posts: 11
Joined: Wed Sep 29, 2021 3:14 pm

Quest Machine not loaded when transitioning between scenes

Post 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.
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine not loaded when transitioning between scenes

Post 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
mightyBond
Posts: 11
Joined: Wed Sep 29, 2021 3:14 pm

Re: Quest Machine not loaded when transitioning between scenes

Post by mightyBond »

The first solution you mentioned worked! Thank you very much Tony!
mightyBond
Posts: 11
Joined: Wed Sep 29, 2021 3:14 pm

Re: Quest Machine not loaded when transitioning between scenes

Post 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?
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine not loaded when transitioning between scenes

Post 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.).
mightyBond
Posts: 11
Joined: Wed Sep 29, 2021 3:14 pm

Re: Quest Machine not loaded when transitioning between scenes

Post 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.
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine not loaded when transitioning between scenes

Post 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?
Post Reply