Skip to content

Actors that outlive their scene

By default an actor lives in its scene. When the scene unloads, the actor’s object is destroyed and the actor leaves the world, and its clan, its family, its schemes and its thinking end with it. A game with several scenes may not want that. This page shows how to let actors outlive a scene, and what still removes them.

On the Intrigue Manager, Actor Home has two values. Read in code as IM.ActorHome.

Value What happens when a scene unloads
Scene (the default) The objects of the scene’s actors are destroyed. The actors leave the world, as before.
World A scene left the right way parks its actors. They stay in the world.

In the editor’s test worlds (Simulation, Scheme Run) the home is always Scene.

With World, unload a scene through IntrigueScenes.Unload. It parks the scene’s actors and then unloads the scene.

Call What it does Source file
IntrigueScenes.Unload(Scene scene) Parks the actors, then calls SceneManager.UnloadSceneAsync. Returns the AsyncOperation, or null when nothing was unloaded. Actors/IntrigueScenes.cs
IntrigueScenes.Unload(string sceneName) The same for the loaded scene with this name. Actors/IntrigueScenes.cs
IntrigueScenes.Unload(Scene scene, out ParkStatus status) The same, and tells you what the park did. Actors/IntrigueScenes.cs
IM.ParkScene(Scene scene) Only parks. Call it right before your own unload. Manager/IM.ActorHome.cs

Example, not compiled. It is built from the signatures above:

// Actor Home is World on the Intrigue Manager.
IntrigueScenes.Unload("Town");

Parking keeps every registered actor whose object is in the scene in the world, with its registry entry, clan, family, schemes, mind and events. The object is switched off and moved out of the scene into a hidden holder, so the actor is out of sight but alive, and its running schemes go on. IM.onActorAway is raised for each, and IM.onActorBack when an actor is back in its scene.

When the scene loads again, its object of each actor hands the actor back. The scene’s object is removed. Its extra components, and the scene’s references to it, are not kept. Put scene-only parts on a child object of yours. Return Pose says where the object stands then: Newcomer (default) where the scene’s object stands, or Kept where it stood when parked.

ParkStatus tells you why nothing was parked: SceneHome (Actor Home is Scene), NoManager, NotLoaded, or Busy (the parked actors are ending right now).

A plain SceneManager.UnloadSceneAsync, or a LoadScene that replaces the scene, is not covered. Unity has no callback before a scene unloads. The scene’s actor objects are destroyed before Intrigues hears of it, so the actors leave the world, exactly as with Actor Home Scene. Use IntrigueScenes.Unload, or call IM.ParkScene right before your own unload.

By default a scene loaded with LoadSceneMode.Single, such as a menu or a quit to title, ends the parked actors, as their scene’s unload would have. End On Scene Load (IM.EndWorldOnSceneLoad) set to Never keeps them through Single loads. Then only IntrigueWorld.End() or a new game ends them. IntrigueWorld.End() returns how many parked actors ended, or 0 on a multiplayer client. Actors in loaded scenes are not touched.

A saved game remembers where each actor lived, and a load brings a parked actor back parked until its scene is there, so a multi-scene game that loads while some saved scenes are not loaded should use Actor Home World, and for a load in place it should load those scenes first.

A load now always brings back every saved actor that has no object in the scene, whether or not there is a Runtime Actor Loader. Earlier builds dropped them. If your game relied on that, do not save those actors.

The revert of a failed load, Revert Same Scene, is refused whenever any actor is parked, even with Actor Home Scene.

A multiplayer client parks its own objects the same way. Presence is machine-local: it is never saved and never sent, and the host’s world is not touched. This ran in the product’s offline tests only, not with two Unity instances.