I'm looking for a pattern to transition between scenes, moving one instance of an object to the next scene and then later returning it to the prior scene, but without destroying the other objects that were in the prior scene. Here is the context:
- When my game loads, it connects to my server to get the list of characters the player can control and instantiates them dynamically from a prefab.
- The loading script moves each character game object to the main scene and then loads that scene.
- The main scene now has the characters, which can be interacted with. So far, so good. One of the commands is to pick a specific character and send them on a task, which has its own task scene.
- I can move that character to the task scene and move them back when the task is completed. However, the other characters who were not on the task and should not be in the task scene are now destroyed because the main scene was unloaded.
I'm looking for a pattern to accomplish this. Most of what I've read suggests using DontDestroyOnLoad, but this actually moves all characters into all scenes, which results in too many characters in the task scene. Another option might be to create a game object that holds all the character information, pass that between scenes and have logic in each scene to re-instantiate the appropriate character[s] in that scene. This feels like a lot of overhead since I have no other reason to be wiping and recreating them constantly. Perhaps a third option is to restructure my game so the task scene is just added to the main scene and shows up as some kind of overlay that blocks/captures input. This sounds messy and likely to have performance issues (targeting Android).
Does anyone have a good pattern for this?