# Changing gamemode at runtime.

**URL:** <https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [December 28, 2016, 7:53pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504 "2016-12-28T19:53:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4efcd70](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4efcd70](https://forums.unrealengine.com/u/anonymous_user_d4efcd70)\
**Post date:** [December 28, 2016, 7:53pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/1 "2016-12-28T19:53:55Z")

</div>

I just wanted to check what was needed to change the gamemode at runtime. I setup a dummy level with all of the current gamemode options desired, and can’t get GetWorld()-\>SetGamMode(url) to change the current GameMode through C++. Being able to change the GameMode at runtime would vastly simplify having to setup hud management, and controls.

I’m trying to change from the normal combat based GemeMode to one that has settings for navigating through text menus.

My current code for changing the GameMode is:

```auto

    FURL url = FURL(NoInit);   
    url.Map = "DialogueUILevel";
    url.Protocol = "unreal";
    if(GetWorld()->SetGameMode(url))
        GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red,
                                         TEXT("DialogueUILevel game mode loaded"));
    else
        GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("game mode not loaded"));

```

---

<div class="post-metadata">

**Author:** ![ScottMichaud](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ScottMichaud](https://forums.unrealengine.com/u/ScottMichaud)\
**Post date:** [December 28, 2016, 8:38pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/2 "2016-12-28T20:38:22Z")

</div>

When you say text menus, do you mean something like a pause menu? Or something like a main menu?

In the case of a pause menu, I would just have that be a small chunk of your PlayerController.

In the case of a main menu, I would have that be a separate level with its own game mode. Before you travel to the game level, store whatever information you need onto you GameInstance subclass (or write out to a file / cloud server / whatever if that makes more sense for your game, but it probably won’t).

I’m pretty sure UE4 doesn’t intend you to swap out the game mode mid-game.

---

<div class="post-metadata">

**Author:** ![smartyMARTY](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/smartymarty/32/678332_2.png) [@smartyMARTY](https://forums.unrealengine.com/u/smartyMARTY)\
**Post date:** [December 28, 2016, 9:11pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/3 "2016-12-28T21:11:29Z")

</div>

> [@zerophase;643545](#):
>
> I just wanted to check what was needed to change the gamemode at runtime. I setup a dummy level with all of the current gamemode options desired, and can’t get GetWorld()-\>SetGamMode(url) to change the current GameMode through C++. Being able to change the GameMode at runtime would vastly simplify having to setup hud management, and controls.
> 
> I’m trying to change from the normal combat based GemeMode to one that has settings for navigating through text menus.
> 
> My current code for changing the GameMode is:
> 
> ```auto
> 
> FURL url = FURL(NoInit);   
> url.Map = "DialogueUILevel";
> url.Protocol = "unreal";
> if(GetWorld()->SetGameMode(url))
> GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red,
> TEXT("DialogueUILevel game mode loaded"));
> else
> GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("game mode not loaded"));
> 
> ```

UWorld::SetGameMode(FURL url) only spawns a new GameMode if the current GameMode (AuthorityGameMode) is null. Since the map is loaded, it is not null.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4efcd70](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4efcd70](https://forums.unrealengine.com/u/anonymous_user_d4efcd70)\
**Post date:** [December 28, 2016, 10:38pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/4 "2016-12-28T22:38:04Z")

</div>

When I say text menus, I mean a dialogue window, like you have in Dragon’s Age or Mass Effect. When that pops up the input and HUD literally changes. I’m trying to do that without breaking the game flow, by having to load a separate scene for every dialogue.

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [December 28, 2016, 10:44pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/5 "2016-12-28T22:44:17Z")

</div>

I’m not entirely sure, but I would say: You can’t change the GameMode without reloading the Level.

I could be wrong here, but I don’t think UE4 is designed to switch out the GameMode in the middle of the game.  
This would also switch out PlayerControllers etc and I doubt that this is easily possible without disconnecting people,  
even in Singleplayer.

If you want to change the GameMode, you can do this:

Pre 4.14, you can add lines to your DefaultGame.ini to add shortcuts. This is done similar to this:

```auto

[/Script/Engine.GameMode]
+GameModeClassAliases=(ShortName="Group and Chat",GameClassName="/Game/BPNetworkingProject/Blueprints/GroupInviteChat/GICGameMode.GICGameMode_C")
+GameModeClassAliases=(ShortName="Free For All",GameClassName="/Game/BPNetworkingProject/Blueprints/DeathmatchLevel/DMGameMode.DMGameMode_C")
+GameModeClassAliases=(ShortName="Team-based",GameClassName="/Game/BPNetworkingProject/Blueprints/TeamDeathmatchLevel/TDMGameMode.TDMGameMode_C")

```

In 4.14 you can do this through the Maps and Modes tab in your Project settings.

This allows you to do this is in the OpenLevel URL:

```auto

open LEVELNAME?game=GameModeShortcut

```

After this, the map will be opened with the new GameMode.

---

<div class="post-metadata">

**Author:** ![ScottMichaud](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ScottMichaud](https://forums.unrealengine.com/u/ScottMichaud)\
**Post date:** [December 28, 2016, 11:07pm UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/6 "2016-12-28T23:07:28Z")

</div>

> [@zerophase;643595](#):
>
> When I say text menus, I mean a dialogue window, like you have in Dragon’s Age or Mass Effect. When that pops up the input and HUD literally changes. I’m trying to do that without breaking the game flow, by having to load a separate scene for every dialogue.

Yeah, I’d do that by having your HUD wrapped in a blank HUD that handles swapping out inner-HUDs when you context switch.

Here’s a similar example of this: [Imgur: The magic of the Internet](http://imgur.com/a/wShCS)

It’s a main menu where the wrapper stores a reference to each sub-screen, and swaps out the required one into the container as needed. You could do the same idea, just with your in-game stuff.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4efcd70](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4efcd70](https://forums.unrealengine.com/u/anonymous_user_d4efcd70)\
**Post date:** [December 29, 2016, 12:14am UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/7 "2016-12-29T00:14:54Z")

</div>

> [@ScottMichaud;643609](#):
>
> Yeah, I’d do that by having your HUD wrapped in a blank HUD that handles swapping out inner-HUDs when you context switch.
> 
> Here’s a similar example of this: [Imgur: The magic of the Internet](http://imgur.com/a/wShCS)
> 
> It’s a main menu where the wrapper stores a reference to each sub-screen, and swaps out the required one into the container as needed. You could do the same idea, just with your in-game stuff.

Thanks, I’ll look into that.

Now, in a more general direction if I was to change the GameMode so it could be switched at Runtime. Is that something Epic is likely to accept?

---

<div class="post-metadata">

**Author:** ![Xenon2112](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xenon2112](https://forums.unrealengine.com/u/Xenon2112)\
**Post date:** [January 28, 2020, 3:26am UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/8 "2020-01-28T03:26:07Z")

</div>

I want to make sure this is high in search results. As eXi mentions above, you can select the game mode via the options string with Game Mode Class Aliases set in the Default Modes section of Maps & Modes in Project Settings. Be sure to click the down arrow to expand the section. Different game modes in the same level for UE4. Multiple game modes for the same level.

Although he’s mentioning the OpenLevel URL, this is also possible with the options string in the OpenLevel node, which might be the same thing.

---

<div class="post-metadata">

**Author:** ![MkMike001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MkMike001](https://forums.unrealengine.com/u/MkMike001)\
**Post date:** [March 11, 2020, 9:07am UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/9 "2020-03-11T09:07:01Z")

</div>

> [@eXi](#):
>
> I’m not entirely sure, but I would say: You can’t change the GameMode without reloading the Level.
> 
> I could be wrong here, but I don’t think UE4 is designed to switch out the GameMode in the middle of the game.  
> This would also switch out PlayerControllers etc and I doubt that this is easily possible without disconnecting people,  
> even in Singleplayer.
> 
> If you want to change the GameMode, you can do this:
> 
> Pre 4.14, you can add lines to your DefaultGame.ini to add shortcuts. This is done similar to this:
> 
> ```auto
> 
> [/Script/Engine.GameMode]
> +GameModeClassAliases=(ShortName="Group and Chat",GameClassName="/Game/BPNetworkingProject/Blueprints/GroupInviteChat/GICGameMode.GICGameMode_C")
> +GameModeClassAliases=(ShortName="Free For All",GameClassName="/Game/BPNetworkingProject/Blueprints/DeathmatchLevel/DMGameMode.DMGameMode_C")
> +GameModeClassAliases=(ShortName="Team-based",GameClassName="/Game/BPNetworkingProject/Blueprints/TeamDeathmatchLevel/TDMGameMode.TDMGameMode_C")
> 
> ```
> 
> In 4.14 you can do this through the Maps and Modes tab in your Project settings.
> 
> This allows you to do this is in the OpenLevel URL:
> 
> ```auto
> 
> open LEVELNAME?game=GameModeShortcut
> 
> ```
> 
> After this, the map will be opened with the new GameMode.

I Tried this with 4.23 Engine And There are minor changes I had to done

It was not DefaultGame.ini, It was DefaultEngine.ini

[/Script/EngineSettings.GameMapsSettings]

+GameModeClassAliases=(Name=“TDMMode”,GameMode=/Game/Blueprints/GameModes/BP\_TDMGameMode.BP\_TDMGameMode\_C)

As Xenon2112 mentioned above, Under Maps & Modes Advanced section Aliases can be added.

---

<div class="post-metadata">

**Author:** ![Xrenyn\_the\_Mage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xrenyn\_the\_Mage](https://forums.unrealengine.com/u/Xrenyn_the_Mage)\
**Post date:** [May 21, 2024, 11:36am UTC](https://forums.unrealengine.com/t/changing-gamemode-at-runtime/81504/10 "2024-05-21T11:36:41Z")

</div>

Just to document this somewhere: The syntax for loading a level with a concrete game mode whose alias is set to “YourGameMode” is

```auto
UGameplayStatics::OpenLevel(
    GetWorld(),
    FName("/Game/Path/To/Your/Level"),
    false,
    "game=YourGameMode"
);

```
