Issue with loading and reading quest state.

Announcements, support questions, and discussion for Quest Machine.
Post Reply
toficor
Posts: 13
Joined: Tue Apr 19, 2022 10:19 am

Issue with loading and reading quest state.

Post by toficor »

Hello,
so I am working with Unity Timeline right now, and I'm trying to use

Code: Select all

m_condition.IsTrue(Player.Instance.transform)
with Lua code condition

Code: Select all

CurrentQuestState("followTheFlame") == "unassigned"
to decited if Timeline should be played or not (this condition variable is a serializeField inside my class responsible for starting Timelines). The reason for this is that some Timelines should only be played once on level load depending on quests state.

I think anything is setup properly. I have set bridge between Dialogue System and Quest Machine.
1.PNG
1.PNG (38.64 KiB) Viewed 1083 times
Quest representation in Dialogue Database has thesame id like the one in the Quest Machine Database.

Save system works properly because, when I saved game after getting quest and load after that I have this quest in my QuestJournal component but Lua condition says that my quest state is still "unassigned" and my Timeline is starting.

For saving and loading I'm using your methods from SaveSystem class.

I'm I missing something? Thank you in advance for all help.

Best Regards.
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: Issue with loading and reading quest state.

Post by Tony Li »

Hi,

Since you're doing this on level load, you may be checking "m_condition.IsTrue(Player.Instance.transform)" before the save system has applied the saved quest journal state to the newly-loaded scene's Quest Journal component.

Instead, check that condition after the save data has been applied. You can use a Dialogue System Trigger set to OnSaveDataApplied or, if you're using a script, change code that looks similar to this:

Code: Select all

void Start()
{
    if (m_condition.IsTrue(Player.Instance.transform))
    {
        // Run timeline.
    }
}
to this:

Code: Select all

void Awake()
{
    PixelCrushers.SaveSystem.saveDataApplied += OnSaveDataApplied;
}
void OnSaveDataApplied()
{
    PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied;
    if (m_condition.IsTrue(Player.Instance.transform))
    {
        // Run timeline.
    }
}
toficor
Posts: 13
Joined: Tue Apr 19, 2022 10:19 am

Re: Issue with loading and reading quest state.

Post by toficor »

That was the fastest response I've ever recieved and it works!!!

Thank you so much.
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: Issue with loading and reading quest state.

Post by Tony Li »

Happy to help!
Post Reply