Quest Control on Scene Load

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Don Angel
Posts: 1
Joined: Sat Feb 22, 2025 5:06 am

Quest Control on Scene Load

Post by Don Angel »

I have 2 scenes, a "town" where you get the quest and a "forest" where you'll complete the quest.

I have it set up so that the quests are persistent between scenes.

What I want to do is that when you go to the "Forest" scene, if you have the FindCoins quest active, it sets to activa a game object with the coins as childs.

Right now, I have a cube in the scene that does that when the player collides with it.
But I'd like it to check if the quest is active when loading the scene.
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Control on Scene Load

Post by Tony Li »

Hi,

Make sure you're changing scenes using the save system. See: How To: Change Scenes With Save System

Then you can add a script with a Start() method that checks the quest state. Example:

Code: Select all

using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using PixelCrushers;
using PixelCrushers.QuestMachine;
public class QuestEventOnStart : MonoBehaviour
{
    public Quest quest;
    public UnityEvent onQuestActive;
    
    IEnumerator Start()
    {
        for (int i = 0; i < SaveSystem.framesToWaitBeforeApplyData; i++) { yield return null; }
        yield return new WaitForEndOfFrame();
        if (QuestMachine.GetQuestState(quest.id) == QuestState.Active)
        {
            onQuestActive.Invoke();
        }
    }
}
Then add this to a GameObject (e.g., empty GameObject) in the Forest scene, assign the quest, and configure the On Start () event.
Post Reply