UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GameModeBase.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Misc/Guid.h"
10#include "GameFramework/Pawn.h"
11#include "GameFramework/Info.h"
13#include "Online/CoreOnline.h"
16#include "GameModeBase.generated.h"
17
18class AGameSession;
19class AGameStateBase;
20class AHUD;
21class APlayerState;
22class ASpectatorPawn;
23class UNetConnection;
24class UPlayer;
25
27
30
46UCLASS(config = Game, notplaceable, BlueprintType, Blueprintable, Transient, hideCategories = (Info, Rendering, MovementReplication, Replication, Actor), meta = (ShortTooltip = "Game Mode Base defines the game being played, its rules, scoring, and other facets of the game type."), MinimalAPI)
47class AGameModeBase : public AInfo
48{
50
51public:
52
53 //~=============================================================================
54 // Initializing the game
55
62 ENGINE_API virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage);
63
70
72 UPROPERTY(BlueprintReadOnly, Category=GameMode)
73 FString OptionsString;
74
75
76 //~=============================================================================
77 // Accessors for classes spawned by game
78
81
83 UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Classes)
85
87 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Classes)
89
91 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category=Classes)
93
95 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category=Classes)
97
99 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category=Classes)
101
103 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Classes, meta = (DisplayName = "HUD Class"))
104 TSubclassOf<AHUD> HUDClass;
105
107 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Classes)
109
111 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category=Classes)
112 TSubclassOf<ASpectatorPawn> SpectatorClass;
113
115 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category=Classes)
117
118 UPROPERTY(EditAnywhere, NoClear, BlueprintReadOnly, Category = Classes)
120
123
124 //~=============================================================================
125 // Accessors for current state
126
130
134
136 template< class T >
137 T* GetGameState() const
138 {
139 return Cast<T>(GameState);
140 }
141
144
146 UFUNCTION(BlueprintCallable, Category=Game)
147 ENGINE_API virtual int32 GetNumPlayers();
148
150 UFUNCTION(BlueprintCallable, Category=Game)
151 ENGINE_API virtual int32 GetNumSpectators();
152
153
154 //~=============================================================================
155 // Starting/pausing/resetting the game
156
158 UFUNCTION(BlueprintCallable, Category=Game)
159 ENGINE_API virtual void StartPlay();
160
162 UFUNCTION(BlueprintCallable, Category=Game)
163 ENGINE_API virtual bool HasMatchStarted() const;
164
166 UFUNCTION(BlueprintCallable, Category=Game)
167 ENGINE_API virtual bool HasMatchEnded() const;
168
177
184 ENGINE_API virtual bool ClearPause();
185
194
196 ENGINE_API virtual bool AllowPausing(APlayerController* PC = nullptr);
197
199 ENGINE_API virtual bool IsPaused() const;
200
208 UFUNCTION(BlueprintNativeEvent, Category=Game)
210
215 UFUNCTION(BlueprintCallable, Category=Game)
216 ENGINE_API virtual void ResetLevel();
217
219 UFUNCTION(BlueprintCallable, Category=Game)
220 ENGINE_API virtual void ReturnToMainMenuHost();
221
223 ENGINE_API virtual bool CanServerTravel(const FString& URL, bool bAbsolute);
224
226 ENGINE_API virtual void ProcessServerTravel(const FString& URL, bool bAbsolute = false);
227
239 ENGINE_API virtual void GetSeamlessTravelActorList(bool bToTransition, TArray<AActor*>& ActorList);
240
249
256
262 ENGINE_API virtual void HandleSeamlessTravelPlayer(AController*& C);
263
268 ENGINE_API virtual void PostSeamlessTravel();
269
271 ENGINE_API virtual void StartToLeaveMap();
272
273
274 //~=============================================================================
275 // Player joining and leaving
276
282 ENGINE_API virtual void GameWelcomePlayer(UNetConnection* Connection, FString& RedirectURL);
283
293 ENGINE_API virtual void PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage);
294
295 DECLARE_DELEGATE_OneParam(FOnPreLoginCompleteDelegate, const FString& /*ErrorMsg*/);
296
303 ENGINE_API virtual void PreLoginAsync(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, const FOnPreLoginCompleteDelegate& OnComplete);
304
323 ENGINE_API virtual APlayerController* Login(UPlayer* NewPlayer, ENetRole InRemoteRole, const FString& Portal, const FString& Options, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage);
324
326 ENGINE_API virtual void PostLogin(APlayerController* NewPlayer);
327
329 UE_DEPRECATED(5.6, "This functionality has been moved into OnPostLogin. You cannot call that function directly, it is executed at the end of PostLogin.")
331
335
336public:
338 UFUNCTION(BlueprintImplementableEvent, Category=Game, meta = (DisplayName = "OnPostLogin", ScriptName = "OnPostLogin"))
340
343
345 UFUNCTION(BlueprintImplementableEvent, Category=Game, meta = (DisplayName = "OnLogout", ScriptName = "OnLogout"))
347
358
359 UE_DEPRECATED(4.20, "SpawnPlayerController with Location and Rotation is deprecated, call or override the version that takes an Option string instead")
361 UE_DEPRECATED(4.20, "SpawnReplayPlayerController is deprecated, replay controller spawning is handled inside the new version of the SpawnPlayerController function")
363
364
366 UFUNCTION(BlueprintNativeEvent, Category=Game)
368
370 UFUNCTION(BlueprintNativeEvent, Category=Game)
372
374 UFUNCTION(BlueprintNativeEvent, Category=Game)
375 ENGINE_API bool CanSpectate(APlayerController* Viewer, APlayerState* ViewTarget);
376
378 UPROPERTY(EditAnywhere, Category=Game)
380
387 UFUNCTION(BlueprintCallable, Category=Game)
388 ENGINE_API virtual void ChangeName(AController* Controller, const FString& NewName, bool bNameChange);
389
396 UFUNCTION(BlueprintImplementableEvent,Category=Game,meta=(DisplayName="OnChangeName", ScriptName="OnChangeName"))
397 ENGINE_API void K2_OnChangeName(AController* Other, const FString& NewName, bool bNameChange);
398
399
400 //~=============================================================================
401 // Spawning the player's pawn
402
410 UFUNCTION(BlueprintNativeEvent, Category=Game)
412
421 UFUNCTION(BlueprintNativeEvent, Category=Game)
422 ENGINE_API AActor* FindPlayerStart(AController* Player, const FString& IncomingName = TEXT(""));
423
432 UFUNCTION(BlueprintPure, Category=Game, meta = (DisplayName = "FindPlayerStart"))
433 ENGINE_API AActor* K2_FindPlayerStart(AController* Player, const FString& IncomingName = TEXT(""));
434
436 UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Game)
438
440 UFUNCTION(BlueprintCallable, Category=Game)
442
444 UFUNCTION(BlueprintCallable, Category=Game)
446
448 UFUNCTION(BlueprintCallable, Category=Game)
450
457 UFUNCTION(BlueprintNativeEvent, Category=Game)
459
466 UFUNCTION(BlueprintNativeEvent, Category=Game)
468
470 UFUNCTION(BlueprintNativeEvent, Category=Game)
472
474 UFUNCTION(BlueprintImplementableEvent, Category=Game, meta = (DisplayName = "OnRestartPlayer", ScriptName = "OnRestartPlayer"))
476
479
480
481 //~=============================================================================
482 // Engine hooks
483
486
488 ENGINE_API virtual bool IsHandlingReplays();
489
491 ENGINE_API virtual bool SpawnPlayerFromSimulate(const FVector& NewLocation, const FRotator& NewRotation);
492
493 //~ Begin AActor Interface
494 ENGINE_API virtual void PreInitializeComponents() override;
496 //~ End AActor Interface
497
505 ENGINE_API virtual bool UpdatePlayerStartSpot(AController* Player, const FString& Portal, FString& OutErrorMessage);
506
517
527
536 ENGINE_API virtual FString InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId, const FString& Options, const FString& Portal = TEXT(""));
537
539 UFUNCTION(BlueprintNativeEvent, Category=Game)
541
547
550
553
556
562
570 ENGINE_API virtual APlayerController* ProcessClientTravel(FString& URL, bool bSeamless, bool bAbsolute);
571
573 ENGINE_API virtual void InitSeamlessTravelPlayer(AController* NewController);
574
576 UFUNCTION(BlueprintImplementableEvent, Category=Game, meta=(DisplayName="OnSwapPlayerControllers", ScriptName="OnSwapPlayerControllers"))
578
581
582public:
584 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=GameMode)
587
589 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=GameMode)
591
593 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=GameMode)
594 uint32 bPauseable : 1;
595
601 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = GameMode)
603
606
607private:
608 // Hidden functions that don't make sense to use on this class.
610};
611
614{
615public:
616
625 DECLARE_EVENT_OneParam(AGameModeBase, FGameModeInitializedEvent, AGameModeBase* /*GameMode*/);
626
634 DECLARE_EVENT_ThreeParams(AGameModeBase, FGameModePreLoginEvent, AGameModeBase* /*GameMode*/, const FUniqueNetIdRepl& /*NewPlayer*/, FString& /*ErrorMessage*/);
635
641 DECLARE_EVENT_TwoParams(AGameModeBase, FGameModePostLoginEvent, AGameModeBase* /*GameMode*/, APlayerController* /*NewPlayer*/);
642
648 DECLARE_EVENT_TwoParams(AGameModeBase, FGameModeLogoutEvent, AGameModeBase* /*GameMode*/, AController* /*Exiting*/);
649
656
657public:
658
659 static FGameModeInitializedEvent& OnGameModeInitializedEvent() { return GameModeInitializedEvent; }
660 static FGameModePreLoginEvent& OnGameModePreLoginEvent() { return GameModePreLoginEvent; }
661 static FGameModePostLoginEvent& OnGameModePostLoginEvent() { return GameModePostLoginEvent; }
662 static FGameModeLogoutEvent& OnGameModeLogoutEvent() { return GameModeLogoutEvent; }
663 static FGameModeMatchStateSetEvent& OnGameModeMatchStateSetEvent() { return GameModeMatchStateSetEvent; }
664
670};
671
672
OODEFFUNC typedef const int const char * function
Definition oodle2.h:710
#define HIDE_ACTOR_TRANSFORM_FUNCTIONS()
Definition Actor.h:5033
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DELEGATE_RetVal(ReturnValueType, DelegateName)
Definition DelegateCombinations.h:41
#define DECLARE_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:48
ENetRole
Definition EngineTypes.h:3346
OnComplete(MoveTemp(Response))
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
EReplicationSystem
Definition NetEnums.h:85
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition Controller.h:41
Definition GameSession.h:28
Definition GameStateBase.h:33
Definition PlayerController.h:261
Definition PlayerState.h:42
Definition ServerStatReplicator.h:18
Definition SpectatorPawn.h:17
Definition GameModeBase.h:614
static FGameModeLogoutEvent & OnGameModeLogoutEvent()
Definition GameModeBase.h:662
static FGameModeMatchStateSetEvent & OnGameModeMatchStateSetEvent()
Definition GameModeBase.h:663
static ENGINE_API FGameModeMatchStateSetEvent GameModeMatchStateSetEvent
Definition GameModeBase.h:669
static ENGINE_API FGameModePreLoginEvent GameModePreLoginEvent
Definition GameModeBase.h:666
static ENGINE_API FGameModeInitializedEvent GameModeInitializedEvent
Definition GameModeBase.h:665
DECLARE_EVENT_OneParam(AGameModeBase, FGameModeMatchStateSetEvent, FName)
static ENGINE_API FGameModePostLoginEvent GameModePostLoginEvent
Definition GameModeBase.h:667
static ENGINE_API FGameModeLogoutEvent GameModeLogoutEvent
Definition GameModeBase.h:668
DECLARE_EVENT_ThreeParams(AGameModeBase, FGameModePreLoginEvent, AGameModeBase *, const FUniqueNetIdRepl &, FString &)
DECLARE_EVENT_TwoParams(AGameModeBase, FGameModePostLoginEvent, AGameModeBase *, APlayerController *)
DECLARE_EVENT_TwoParams(AGameModeBase, FGameModeLogoutEvent, AGameModeBase *, AController *)
DECLARE_EVENT_OneParam(AGameModeBase, FGameModeInitializedEvent, AGameModeBase *)
static FGameModePostLoginEvent & OnGameModePostLoginEvent()
Definition GameModeBase.h:661
static FGameModeInitializedEvent & OnGameModeInitializedEvent()
Definition GameModeBase.h:659
static FGameModePreLoginEvent & OnGameModePreLoginEvent()
Definition GameModeBase.h:660
Definition NameTypes.h:617
Definition UnrealType.h:3087
Definition Text.h:385
Definition Array.h:670
Definition SubclassOf.h:30
Definition Class.h:3793
Definition NetConnection.h:284
Definition Player.h:18
bool IsPaused()
Definition OnlineReplStructs.h:26
Definition ObjectPtr.h:488