GameFramework¶
5 tools for game mode classes and overrides, player starts and spawn points.
Back to the index.
get_game_mode_info¶
Read-only
Read which classes a game mode spawns: DefaultPawnClass, HUDClass, PlayerStateClass, GameStateClass, SpectatorClass and PlayerControllerClass from the class default object of an AGameModeBase subclass, native or Blueprint, plus its parent class, is_multiplayer (true when it derives from AGameMode, the match-state subclass) and the GameMode override in the open editor level's World Settings. Read-only. An empty string means that slot or override is unset; a class that does not resolve or is not a game mode is an error. Change the slots with set_game_mode_classes and the level override with set_game_mode_override; the project-wide default is the GlobalDefaultGameMode of GameMapsSettings (get_project_settings_value), and get_world_settings reads the rest of World Settings.
| Parameter | Type | Required | Description |
|---|---|---|---|
game_mode_class |
string | no | Game mode class by name or path: a native short name with or without the A prefix ('GameModeBase'), a /Script path, or a Blueprint asset or class path, e.g. '/Game/Core/BP_MyGameMode'. One of the two class params is required. |
game_mode_class_path |
string | no | Full class path, e.g. '/Script/Engine.GameModeBase' or '/Game/Core/BP_MyGameMode.BP_MyGameMode_C'; tried before game_mode_class. |
Returns: { game_mode_class: string, parent_class: string, is_multiplayer: bool, default_pawn_class: string, hud_class: string, player_state_class: string, game_state_class: string, spectator_class: string, player_controller_class: string, world_settings_default_game_mode?: string }
register_spawn_point¶
Additive
Mark an existing actor as a registered spawn point for the project (sets PlayerStartTag + ensures it's a APlayerStart). Useful for tagging generic actors as respawn anchors in lieu of placing APlayerStarts.
| Parameter | Type | Required | Description |
|---|---|---|---|
actor_name |
string | yes | Name or label of the actor to mark as a spawn point. |
player_start_tag |
string | no | Optional FName tag (e.g. "Red"/"Blue" for team filtering; "Respawn" for general spawn anchors). |
Returns: { actor_name, was_player_start, promoted_to_player_start: bool, player_start_tag }
set_game_mode_classes¶
Destructive Idempotent
Write one or more class slots -- DefaultPawnClass, HUDClass, PlayerStateClass, GameStateClass, SpectatorClass, PlayerControllerClass -- on the class default object (CDO) of an AGameModeBase subclass, picked by game_mode_class_path or else game_mode_class (one is required). Pass at least one slot param; each must resolve to a class deriving from that slot's base, and every one is checked before anything is written, so a bad one writes nothing. A slot that already holds the class is left alone (idempotent). GameModes spawned later (the next PIE) use the new classes. A Blueprint GameMode's CDO is modified and its package marked dirty but not saved: persist it with save_asset (persistable true). A native GameMode class has no savable package, so its values last only until the editor closes (persistable false). Each slot written is read back from the CDO. Read every slot with get_game_mode_info; set_game_mode_override picks the GameMode of the level.
| Parameter | Type | Required | Description |
|---|---|---|---|
game_mode_class |
string | no | Optional AGameModeBase class name (short or /Script/ path) |
game_mode_class_path |
string | no | Optional long /Script/Engine.GameModeBase path (takes precedence) |
pawn_class |
string | no | Optional APawn-derivative class for DefaultPawnClass |
hud_class |
string | no | Optional AHUD-derivative class for HUDClass |
player_state_class |
string | no | Optional APlayerState-derivative class for PlayerStateClass |
game_state_class |
string | no | Optional AGameStateBase-derivative class for GameStateClass |
spectator_class |
string | no | Optional ASpectatorPawn-derivative class for SpectatorClass |
player_controller_class |
string | no | Optional APlayerController-derivative class for PlayerControllerClass |
Returns: { game_mode_class: string, persistable: bool, default_pawn_class?: string, hud_class?: string, player_state_class?: string, game_state_class?: string, spectator_class?: string, player_controller_class?: string, already_set: bool, slots_written: [string] } -- one read-back field per slot that was passed; already_set is true when every requested slot already held its class (nothing written), and slots_written names the reply fields of the slots that changed.
set_game_mode_override¶
Destructive Idempotent
Set -- or, with game_mode_class "" or "None", clear -- the GameMode override in the World Settings of the current editor world (AWorldSettings::DefaultGameMode), the GameMode this level uses instead of the project default; a cleared override falls back to the engine's URL/INI DefaultGameMode on the next world load. game_mode_class can be a native class name, a /Script/ path or a Blueprint GameMode asset path, and must derive from AGameModeBase (AGameMode too; is_multiplayer says which). The World Settings actor is modified as part of the call's undo step and the level is marked dirty but not saved: persist it with save_level. Repeating the call leaves the same state (idempotent). An unknown or non-GameMode class, or no editor world, is an error. Read it back with get_game_mode_info; the GameMode's own class slots are set with set_game_mode_classes, and a GameMode Blueprint is made with create_blueprint (parent_class "GameModeBase").
| Parameter | Type | Required | Description |
|---|---|---|---|
game_mode_class |
string | yes | AGameModeBase-derivative class: a native short name (e.g. "GameModeBase"), a /Script/ path, or a Blueprint GameMode asset path (e.g. "/Game/Core/BP_MyGameMode"). An empty string or "None" clears the override. |
Returns: { world_settings_path: string, world_name: string, default_game_mode: string, previous_default_game_mode: string, reset: bool, is_multiplayer?: bool } -- default_game_mode is "" and reset true when the override was cleared; previous_default_game_mode is the path of the override before the call ("" when there was none); is_multiplayer only when a class was set.
spawn_player_start¶
Additive
Place a Player Start (where the game mode spawns players) in the editor's current level, with an optional rotation and team tag; when name matches the label or object name of an existing Player Start, that one is moved and retagged instead of adding another. Use it to set where players appear; spawn_actor can also place one (type PlayerStart) but without the tag or the rotation check; to make an actor already in the level a tagged spawn point use register_spawn_point; which pawn spawns there is set_game_mode_classes. Location and rotation are read back from the actor: a mismatch, usually a [Pitch, Yaw, Roll] array sent with the yaw last, answers success false with both values. One undo step; the level is marked dirty but not saved (save_level). Without name every call adds a new Player Start.
| Parameter | Type | Required | Description |
|---|---|---|---|
location |
array | no | [X, Y, Z] world location in centimetres; put it a little above the floor so the pawn's capsule does not start inside it. |
rotation |
array | no | Optional world rotation. TWO forms: the unambiguous OBJECT form {"roll":R,"pitch":P,"yaw":Y} (RECOMMENDED) or the ambiguous ARRAY form [Pitch, Yaw, Roll] -- note the array order, index 2 is ROLL, not yaw. Default identity. |
player_start_tag |
string | no | Optional PlayerStartTag, e.g. "Red", "Blue", "Spectator": the game mode's FindPlayerStart picks starts by this tag (the Portal argument); empty leaves the current tag unchanged. |
name |
string | no | Optional actor label, e.g. "PS_RedBase"; an existing Player Start with this label or object name is reused. Without it the engine names the new actor (PlayerStart_N) and every call adds one. |
Returns: { actor_name, location: [x,y,z] (RE-READ from the actor), rotation: {roll,pitch,yaw} (RE-READ from the actor, axes NAMED), is_spatially_loaded: bool, location_matches_request: bool, rotation_matches_request: bool, player_start_tag, spawned: bool, already_existed: bool, requested: { location, rotation, player_start_tag, name } }