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.
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.
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.
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:
[/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:
open LEVELNAME?game=GameModeShortcut
After this, the map will be opened with the new GameMode.
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.
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.