Sending an NPC to another scene
One call moves an NPC that is far away into another scene.
NpcActions moving a far-away NPC to another scene
ChangeLevel moves the NPC into the scene you name. Check Npcs.Get(id).CurrentScene afterwards to see where it is.
public static class NpcActions
{
public static bool ChangeLevel(int npcId, string scene);
}
| Method | Returns | What it does |
|---|---|---|
ChangeLevel(npcId, scene) | bool | Moves a far-away NPC to another scene. |
Things to know
ChangeLevelmoves an NPC that is not in your scene into the scene you name. The NPC does not walk there. The game puts it there at once. (It calls the game’sNPCSceneUtilities.ChangeNPCLevel.)ChangeLevelgivestruewhen the NPC now belongs to that scene, which does not mean you can see it. You can check withNpcs.Get(id).CurrentScene. Ifsceneis the one that is loaded, the game spawns the NPC at a level-change door of that scene: the door to its old level, or else the first door it finds. With no door, the game logs an error and the NPC appears the next time that scene loads.- The change stays in memory until the next game save, and then it is saved. The saved fields are the scene, the time spent in the level (the game resets it to 0), and the position, which the framework clears so the NPC does not reuse coordinates from its old level. With the position cleared, the game uses the NPC’s scheduled spot instead. The NPC’s path is not changed. (The fields are
currentScene,timeInLevelandcurrentPosition.activePathis not changed.)
Limits
ChangeLevelgivesfalseand changes nothing in these cases:- A save is loading or being written.
sceneis empty, orsceneis not a scene in the game.- The NPC id is not known, or the NPC is already in
scene. - The NPC is in the scene you are in. The game’s save would write the loaded scene back into the NPC, and there is no way to take a live NPC out of the scene.
- The NPC is walking between scenes, or it is following a target. The game moves those NPCs by itself.
- The NPC’s timetable puts it in a different scene and its scheduler is on. The game’s own update would move it again, and the framework does not switch the scheduler off. (The checks are
SaveController.CheckIfLevelExists,data.Controller != null,data.state.activePath != null,CurrentActivity.GetFollowTarget() != null, and the timetable scene fromcurrentScheduledAction.activity.GetTargetScene()whileschedulerDisabledis false.)