[SOLVED] Saving Spawns

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

[SOLVED] Saving Spawns

Post by mschoenhals »

Hi,
Is there a simple way to save a spawn created by a quest giver? Right now, if an item spawns by a quest giver and the player changes scenes, the spawn will be gone when the player returns. The spawn item right now has a sphere collider (with trigger selected), a Trigger Event with Set Active and also Send To Message System, and a Quest Control script on it. The Quest Giver is using Control Spawner as an action.
Thanks in advance.
Last edited by mschoenhals on Sat May 02, 2020 3:06 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] Saving Spawns

Post by Tony Li »

Hi,

Add a Spawned Object component to your spawn GameObject, and save it as a prefab. Configure the spawner to spawn this prefab. The Spawned Object component adds some saver info fields, but you can leave them blank.

Then add a Spawned Object Manager component to the scene. Make sure it's on a regular scene object, not one that is marked Don't Destroy On Load. Add your spawn prefab to the Spawned Object Prefabs list.

You can find more info about Spawned Object Manager in the Save System Manual, which is in Quest Machine's Documentation folder.
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: [HELP] Saving Spawns

Post by mschoenhals »

Yup, that worked. I see that in the save documentation that Save Across Scene wasn't selected, and I left mine unselected, and it still worked. Not sure what the purpose is for that option. Anyways, working fine now. Thanks so much for your help. :D
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: [SOLVED] Saving Spawns

Post by Tony Li »

Glad to help! :-)
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: [SOLVED] Saving Spawns

Post by mschoenhals »

What if the spawned objects are related to a quest? After the quest has ended, the spawned objects should end. However, when using the Spawned Object Manager along with the Spawned Object component on the prefab(s), the objects continue to spawn. How do I end the spawning?

Also, is the Spawned Object Manager used for enemies who spawn for a specific quest (and therefore no longer spawn after the quest ends)?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: [SOLVED] Saving Spawns

Post by Tony Li »

Hi,

To stop spawning when the quest ends, use the Spawner Quest Action in your quest -- for example, in the quest's Success > Actions section. add a Spawner Quest Action set to Despawn. This will stop the spawner and despawn all spawned objects. If you only want to stop spawning new objects (or enemies) but leave the existing ones in the scene, set the Spawner Quest Action to Stop.
Tzirrit
Posts: 3
Joined: Tue Apr 28, 2020 3:42 pm

Re: [SOLVED] Saving Spawns

Post by Tzirrit »

Hello,

I have a simmilar problem:
A spawner in the scene spawns NPCs as soon as the game starts. I've added a SpawnedObject component to the NPC prefabs and a SpawnedObjectManager to an active GameObject in the scene (parent object to the spawner which spawns the NPCs). However, when laoding the game, previously spawned entities are gone.

Thanks in advance.
Last edited by Tzirrit on Wed Jul 08, 2020 5:39 am, edited 1 time in total.
Tzirrit
Posts: 3
Joined: Tue Apr 28, 2020 3:42 pm

Re: [SOLVED] Saving Spawns

Post by Tzirrit »

I continued debugging and found that the extended spawner script I used changed the spawned object name, so the script could not find the correct prefab.

After fixing that, it got even more interesting/confusing: I created another simpler spawner for testing purposes. That spawner has one npc prefab (with SpawendObject attached). It correctly spawns 3 NPCs and also stores them in the SpawnedObjectManager.
When loading the game, the previously spawned 3 NPCs are created, BUT not registered with the spawner. It just starts spawning more NPCs.

Since SpawnedEntities are handled different than SpawnedObjects, do I need to create a special SpawnedEntitiesSaver that would then tell the spawner to spawn as many entites as were saved before? Or is there already a script for that which I am missing?
Last edited by Tzirrit on Wed Jul 08, 2020 8:41 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: [SOLVED] Saving Spawns

Post by Tony Li »

Hi,

I'll look into this. I believe I implemented it for the upcoming version 1.2.8 which is being released this week.
Tzirrit
Posts: 3
Joined: Tue Apr 28, 2020 3:42 pm

Re: [SOLVED] Saving Spawns

Post by Tzirrit »

Hi Tony,

thanks for looking into it!
Post Reply