Page 1 of 2
[SOLVED]Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 10:41 am
by mschoenhals
Hi,
I'm putting together a quest that upon completion (success state) a GameObject will appear in the Scene and stay there for the duration of the gameplay. I am also using the Dialogue System to handle the quest conversation.
I've tried to accomplish this in two ways: Enable a GameObject (that is currently disabled in the Scene) and also by Instantiating the GameObject prefab. Enable GameObject appears to work early in the Quest (like during the Start state) but will not work in the success state.
The quest does go to another scene (a quick cut scene) and then comes back to the original scene of the quest. There is an error warning:
Code: Select all
Save System: No DataSerializer found on Save System. Adding JsonDataSerializer.
Quest Machine: GetQuestState(blueCrystal): Couldn't find a quest with ID 'blueCrystal'.
UnityEngine.Debug:LogWarning(Object)
The rest of the quest does work. That is, the Journal continues to show the correct state of the Quest, the HUD shows the tracking info, and the alert text is correct.
I do have the save system in place. On my Saving System, which is a persistent object, I do have the Json Data Serializer. When the other scene loads (after the first scene quest has started), the No DataSerializer alert does appear. If I pause, I can see in the DontDestroyOnLoad the Json Data Serializer component attached to my Save System though. The HUD continues to display the correct info, and then the game returns to the previous scene.
Then I get the Quest Machine error couldn't find quest with ID blueCrystal. However, the quest does continue properly to the completion state (journal updates correctly as well). The HUD shows the correct state throughout the scene changes.
My custom Saving System script includes the following lines for Capture and Restore:
Code: Select all
string s = PixelCrushers.SaveSystem.Serialize(PixelCrushers.SaveSystem.RecordSavedGameData());
state["questMachine"] = s;
PixelCrushers.SaveSystem.ApplySavedGameData(PixelCrushers.SaveSystem.Deserialize<SavedGameData>(s));
So, my questions are:
- How do I get a gameObject to appear and stay after the completion of a quest?
- How do I fix the alert issues?
Thank you very much for your help in advance.
Re: Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 11:17 am
by Tony Li
Hi,
Does your scene have two SaveSystem components? Perhaps one is on the Dialogue Manager or some other GameObject? If so, it's possible that the Save System is finding this other SaveSystem component and not using the one you intend. Make sure you only have one SaveSystem component.
Also, if you call a Save System method such as SaveSystem.RecordSavedGameData() before the scene has a SaveSystem component, the Save System will have to create a new, empty GameObject with a SaveSystem component. This may be what's happening.
Maybe that issue is affecting the Enable GameObject action. Please fix the Save System issue first. Then check if Enable GameObject works.
Re: Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 1:14 pm
by mschoenhals
It looks like it may be that there are 2 saving systems; one of which is being added in the second scene. That is, when I check my PersistentObjects prefab, it has my custom save prefab called "SavingSystem" attached to it. No other Save System appears on it. When I start up the scene, there is still only the one SavingSystem on the PersistentObjects in the Hierarchy. But, when I go into another scene, a "Save System" appears on the PersistentObjects. Note: it calls it "Save System" so I think its been added automatically as you suggested. Checking in the Hierachy of the second scene, there is no GameObject with an attached "Save System" when the game is not running; it gets added only when switching into the scene.
Neither Quest Machine nor Dialogue Manager prefabs have a jSon Data serializer or a Save System attached.
The code:
Code: Select all
string s = PixelCrushers.SaveSystem.Serialize(PixelCrushers.SaveSystem.RecordSavedGameData());
state["questMachine"] = s;
mentions "SaveSystem" - is that why Quest Machine is adding a new Save System? My prefab is called "SavingSystem."
If the SavingSystem is a persistent object, can SaveSystem.RecordSavedGameData() actually be called before the scene has a SaveSystem component? I have other saved game data like inventory that continues to work and some quest data does continue such as the journal and HUD across various scenes.
My persistentObjects prefab has the following components on the SavingSystem GameObject:
- Saving System
- Saving Wrapper
- Json Data Serializer
- Player Prefs Saved Game Data Storer
Re: Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 3:37 pm
by Tony Li
The SaveSystem component on your SavingSystem GameObject should prevent the Save System from creating a new GameObject named "Save System". I'd like to focus on this issue because it may be the root cause of the other issue.
Would it be possible for you to send me a
reproduction project?
Re: Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 5:41 pm
by mschoenhals
Hi Tony,
I sent you a link to my project via email. Lots of errors due to stripping the project but the issues listed above still come up. To reproduce, click on the little wizard guy and accept the quest. Then go to the blue crystal in the background. A short scene will appear and then go back to the initial scene. You'll see the Json Save error and missing Quest ID error in the console.
Re: Enable Gameobject not working Across Scenes
Posted: Sun Sep 06, 2020 7:32 pm
by Tony Li
Hi Mike,
Thanks for sending the project. Your SavingSystem prefab doesn't have a SaveSystem component. Try adding that component.
I forgot to answer this one earlier:
mschoenhals wrote: ↑Sun Sep 06, 2020 10:41 amHow do I get a gameObject to appear and stay after the completion of a quest?
Add an ActiveSaver component to a GameObject that's guaranteed to be active when the scene starts. Assign the GameObject that can be active or inactive to the ActiveSaver's GameObject To Watch field.
The warning will still be present, however. I'll work on a patch. I see what's going on with it. Ezmore's quest list is restoring first from the save data. While restoring, it checks the offer conditions on the greenCrystal quest, which queries the state of the player's blueCrystal quest. But the player's quest list hasn't restored itself from the save data yet, so it reports that warning. In your case, it has no bad effect because your conversation checks the blueCrystal state well after all characters have restored their save data. When restoring save data, all characters will need to restore their quest lists first, and then they can check offer conditions.
Re: Enable Gameobject not working Across Scenes
Posted: Mon Sep 07, 2020 9:31 am
by mschoenhals
Thanks Tony!
Looks like it's working perfectly. Your help is much appreciated.
Re: [SOLVED]Enable Gameobject not working Across Scenes
Posted: Mon Sep 07, 2020 9:39 am
by Tony Li
Glad to help! I'll be working on the patch today to get rid of that warning message.
Re: [SOLVED]Enable Gameobject not working Across Scenes
Posted: Mon Sep 07, 2020 10:36 am
by Tony Li
Hi,
Please give this patch a try. It should get rid of that warning:
QM_LoadPatch_2020-09-07.unitypackage
This fix will also be in the next full release version.
Re: [SOLVED]Enable Gameobject not working Across Scenes
Posted: Mon Sep 07, 2020 1:56 pm
by mschoenhals
3 errors appeared in the console after I patched QM:
- Assets\Plugins\Pixel Crushers\Quest Machine\Scripts\Quest MonoBehaviours\Quest List\QuestListContainer.cs(322,99): error CS0117: 'QuestMachineMessages' does not contain a definition for 'CheckOfferConditionsMessage'
- Assets\Plugins\Pixel Crushers\Quest Machine\Scripts\Quest MonoBehaviours\Quest List\QuestListContainer.cs(335,73): error CS0117: 'QuestMachineMessages' does not contain a definition for 'CheckOfferConditionsMessage'
- Assets\Plugins\Pixel Crushers\Quest Machine\Scripts\Quest MonoBehaviours\Quest List\QuestListContainer.cs(335,73): error CS0117: 'QuestMachineMessages' does not contain a definition for 'CheckOfferConditionsMessage'
I also got 2 warnings:
- Assets\Plugins\Pixel Crushers\Quest Machine\Scripts\Quest MonoBehaviours\Quest List\QuestJournal.cs(90,29): warning CS0114: 'QuestJournal.OnMessage(MessageArgs)' hides inherited member 'QuestListContainer.OnMessage(MessageArgs)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
- Assets\Plugins\Pixel Crushers\Quest Machine\Scripts\CheckQuestState.cs(8,33): warning CS0649: Field 'CheckQuestState.prefabOfNPC' is never assigned to, and will always have its default value null