Page 1 of 1
[SOLVED] Activate GameObject in another scene
Posted: Fri Jan 31, 2020 9:12 am
by mschoenhals
Hi,
I'm trying to setup a Quest that includes a GameObject (NPC) in another scene that is Activated only if the player has the quest. I saw a short post about using a persistent GameObject but isn't Quest Machine already a persistent GameObject? Is the persistent GameObject in the Quest Giver scene or the scene with the triggered GameObject (NPC)?
Is it possible to disable that GameObject after the player has left that scene? What I'm trying to do is enable an NPC in one scene if the player get's a particular Quest, have the player finish the Quest in that scene, then have that NPC appear back in the original Quest Giver scene. Probably sounds confusing...
Thanks in advance.
Re: Activate GameObject in another scene
Posted: Fri Jan 31, 2020 9:37 am
by Tony Li
Hi,
Unless you've set this NPC to "Don't Destroy On Load", it will only exist in the scene(s) it is in at design time. A common approach is to add a separate instance of the NPC in each scene. In each scene, only activate the NPC's GameObject if it's appropriate for the current state of the quest.
If you're using the Dialogue System in addition to Quest Machine, you can add a PersistentActiveData component to the NPC, or to a separate GameObject if the NPC GameObject starts inactive in the scene. Tick Check On Start, and set the Condition section to check the quest is in the required state to show the NPC.
If you're not using the Dialogue System, you can add a small script (or PlayMaker FSM, etc.) that checks the quest state and sets the NPC active/inactive accordingly.
Re: Activate GameObject in another scene
Posted: Mon Feb 03, 2020 8:46 am
by mschoenhals
I am going to use the Dialogue System - but I'm implementing the Quest System first. I'd like to use a script, how do I check the state of a particular quest then?
Re: Activate GameObject in another scene
Posted: Mon Feb 03, 2020 9:30 am
by Tony Li
Hi,
If your scene has only one QuestJournal (e.g., on the player), check
QuestMachine.GetQuestState("quest ID").
If your scene has multiple QuestJournals (e.g., multiplayer), get a player's QuestJournal component and use FindQuest("quest ID").GetState().
Re: Activate GameObject in another scene
Posted: Tue Feb 04, 2020 9:28 am
by mschoenhals
I think I'm getting some of the syntax wrong. I do have only one Quest Journal (single player game). I'm trying to see the enum value of the Quest State:
Code: Select all
if (QuestMachine.GetQuestState("rescueEzmore") == Successful)
{
print("Rescue Ezmore is in Successful State");
}
However, it doesn't seem to know what "Successful" is.
Re: Activate GameObject in another scene
Posted: Tue Feb 04, 2020 9:49 am
by Tony Li
Make sure this line is near the top of your script:
And change the code to:
Code: Select all
if (QuestMachine.GetQuestState("rescueEzmore") == QuestState.Successful)
{
print("Rescue Ezmore is in Successful State");
}
Tip: If you're using Visual Studio (VS), you can usually right-click on any error that VS has underlined in red. This will open a context menu. Select the first item in the context menu to get some options how to automatically fix it. In the case above, the context menu would offer to change "Successful" to "QuestState.Successful".
Re: Activate GameObject in another scene
Posted: Wed Feb 05, 2020 9:09 am
by mschoenhals
Thanks Tony. That worked really well. I don't have the context menu on my version of Visual Studio. I'm going to check it out and see if I can get it installed. Great tip! Thanks.
Re: [SOLVED] Activate GameObject in another scene
Posted: Wed Feb 05, 2020 9:13 am
by Tony Li
Glad to help!