Travel
This page uses Transform from Unity. The glossary says what each one is.
Travel moves the player between places in a level. An entrypoint is a named spawn point in a level. The game uses entrypoints for level changes and for teleports inside a level.
Travel spawn points and teleports
Use it to list the spawn points in the loaded level, teleport the player to one, and add or remove your own spawn points.
public static class Travel
{
public static bool UsingMinitrain { get; }
public static List<string> Entrypoints();
public static bool TeleportTo(string name);
public static bool OpenFastTravelMenu();
public static bool AddEntrypoint(string name, Transform location);
public static bool AddEntrypoint(string modId, string name, Transform location);
public static bool RemoveEntrypoint(string name);
public static bool RemoveEntrypoint(string modId, string name);
}
| Property | Type | What it means |
|---|---|---|
UsingMinitrain | bool | true when the player is riding the minitrain. |
| Method | Returns | What it does |
|---|---|---|
Entrypoints() | List<string> | The names of the spawn points in the loaded level. |
TeleportTo(name) | bool | Moves the player to the spawn point with this name. |
OpenFastTravelMenu() | bool | Opens the game’s fast travel panel. |
AddEntrypoint(name, location) | bool | Adds a named spawn point to the loaded level. |
AddEntrypoint(modId, name, location) | bool | The same, filed under your mod’s id. |
RemoveEntrypoint(name) | bool | Removes a spawn point that AddEntrypoint added. |
RemoveEntrypoint(modId, name) | bool | Removes a spawn point that your mod added. |
Things to know
Entrypoints()lists the level’s named spawn points. (The names are thePlayerLevelEntrypoints.)TeleportTo(name)moves the player to that spawn point the way the game does. It also sets off the spawn point’s own outputs. (It runsPlayerLevelEntrypoints.Entrypoint.TeleportPlayer.)OpenFastTravelMenu()opens the game’s fast travel panel, the same as the Fast Travel object does. It does nothing if the panel is already open. It changes no saved state, so it also works while a save is busy. (It callsFastTravelController.ToggleMenu, and it does not check the save gate.)AddEntrypointadds a spawn point that the game can find by name. After that, a level change or a door whose target spawn point is that name places the player atlocation.AddEntrypointreturnsfalsefor an empty name, anulllocation, no loaded level, or a name the level already has, so a level’s own spawn point is never replaced. The new spawn point is added after the level’s own, so the game still picks the level’s first spawn point as its default.RemoveEntrypointremoves only a spawn point thatAddEntrypointadded. It returnsfalsefor a level’s own spawn point, so the game’s spawn points can’t be removed. Call it before you destroy theTransformyou passed: the spawn point keeps that transform, and a teleport or level change to that name would use a destroyed object.AddEntrypointandRemoveEntrypointwork while a save is busy, and they write nothing to the save. That is why you can add the spawn point again fromEvents.SceneLoaded.- With several mods, pass your mod id.
RemoveEntrypoint(modId, name)removes only a spawn point that the samemodIdadded, so another mod can’t remove yours. - The versions without
modIdshare one common owner, and they can’t remove a spawn point that was added with a mod id. If an add is refused because the name already exists, one warning in the log names who holds the name. An invalidmodIdthrows anArgumentException.
Limits
- The fast travel menu’s own list of places is built inside a part of the game that the framework can’t read, so it is not available. (The fast travel list is built inside a UI prefab that is not in the DLL.)
- The spawn point lasts only until the level changes. It lives in the loaded level’s list, so a scene change drops it. Add it again each time the level loads, for example in an
Events.SceneLoadedhandler. - A spawn point from a mod can be chosen as the game’s fallback spawn for NPCs. The game picks a random spawn point for NPCs from the whole list, and leaves out only
UnderMapDrop, so your spawn point can be picked. (The game call isGetRandomEntrypoint.)