Keep actors when their scene unloads
Goal: a character from the town scene is still alive, with its clan and its schemes, after you leave the town.
By default an actor lives in its scene. When the scene unloads, the actor leaves the world. This recipe changes that.
- Select the Intrigue Manager. Set Actor Home to World. Two more rows appear: Return Pose and End On Scene Load.
- Stop unloading scenes with
SceneManager.UnloadSceneAsync. Unload them throughIntrigueScenes.Unload. Example. Compiled against the package’s runtime assembly; not run in Unity. The signatures are fromIntrigueScenes.cs:
IntrigueScenes.Unload("Town");- Load the scene again when the player returns. Each actor’s new object hands the actor back.
| Signature | What it does |
|---|---|
static AsyncOperation Unload(Scene scene) |
Parks the scene’s actors, then unloads the scene. Returns null when nothing was unloaded. |
static AsyncOperation Unload(string sceneName) |
The same for the loaded scene with this name. |
static AsyncOperation Unload(Scene scene, out ParkStatus status) |
The same, and says what the park did. |
static ParkStatus ParkScene(Scene scene) on IM |
Only parks. Call it right before your own unload. |
You will see: the actors are out of sight but alive. Their schemes go on. IM.onActorAway is raised for each, and IM.onActorBack when one is back in its scene.
Choose how they come back
Section titled “Choose how they come back”Return Pose is Newcomer (the actor stands where the scene’s own object stands) or Kept (where it stood when parked). Put scene-only parts on a child object of yours: the scene’s own object of the actor is removed, with its extra components.
What can go wrong
Section titled “What can go wrong”- The actors vanish with the scene: you used a plain
SceneManager.UnloadSceneAsyncor aLoadScenethat replaces the scene. Unity gives no callback before an unload, so Intrigues hears too late. UseIntrigueScenes.Unload, or callIM.ParkScenefirst. - Nothing is parked: Actor Home is Scene (
ParkStatus.SceneHome), there is no manager, the scene is not loaded, or the parked actors are ending now. - The parked actors end when you load a menu: a scene loaded as
Singleends them by default. Set End On Scene Load to Never to keep them through such loads. - Parked actors you want gone are still there: only a new game,
IntrigueWorld.End()or aSinglescene load (with End On Scene Load at its default) ends them.
More: Actors that outlive their scene and Intrigue Manager.