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.
[SOLVED] Activate GameObject in another scene
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
[SOLVED] Activate GameObject in another scene
Last edited by mschoenhals on Wed Feb 05, 2020 9:10 am, edited 1 time in total.
Re: Activate GameObject in another scene
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.
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.
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Re: Activate GameObject in another scene
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
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().
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().
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Re: Activate GameObject in another scene
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:
However, it doesn't seem to know what "Successful" is.
Code: Select all
if (QuestMachine.GetQuestState("rescueEzmore") == Successful)
{
print("Rescue Ezmore is in Successful State");
}
Re: Activate GameObject in another scene
Make sure this line is near the top of your script:
And change the code to:
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".
Code: Select all
using PixelCrushers.QuestMachine;
Code: Select all
if (QuestMachine.GetQuestState("rescueEzmore") == QuestState.Successful)
{
print("Rescue Ezmore is in Successful State");
}
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Re: Activate GameObject in another scene
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
Glad to help!