Change gamemode on loading a new level.

Hello,

I need to change the current gamemode to a different gamemode when the level changes. This is due to a great deal of logic being built into the controller, that I do NOT want to execute until a certain level is loaded.

How can I change the gamemode when I load a new level?

For instance: (level 1: gamemodeA) (Level2:gamemodeB)

*also if what I am asking is not possible, can the default controller be changed on level load instead?

Thanks very much for your help.

Hey spacetackle,

It’s 100% possible to change gamemodes between levels. In your level’s world settings, under the game mode section, you are able to select your own gamemode in the gameMode override dropdown. You can create a new game mode by clicking the ‘+’ next to the game mode dropdown

214841-gamemode.png

2 Likes

hey spacetackle did this help?

thinking about this now. What if you want to use the same level with multiple game modes? For instance sometimes the map is Deathmatch and sometimes it’s CaptureTheFlag.

Is the solution to have small wrapper levels that pull in the game logic then load a sub-level with the world assets?

Another related question is where should we be putting runtime code that needs to update all the time? For instance your social feed that happens in the main menu AND whatever mode you are playing. At the moment I have this updated from a GameMode class because the GameInstance class doesn’t have a tick function but that’s going to become messy with multiple game modes.

Perhaps the main game logic needs to be in a plugin, with a Tick function. I’ve been sort of dancing around that idea for a while, beyond the massive earthquake in source control this would imply I’m not sure what the implications are. The way Unreal is structured though this seems like a fairly attractive way to encapsulate the overall game behavior.

I know this is super old, but I wanted to comment with what worked for me.

In my HUD widget (I was working on a simple main menu that lets me choose game modes), I used Open Level to load the level and added this as a parameter in the options input:

?Game=/Game/Player/Blueprints/ThirdPersonGameMode.ThirdPersonGameMode_C

Don’t be fooled, the _C at the end will not be in the name of your game mode. If it is, you might need another _C at the end. This is awful design in my opinion, as nothing anywhere in my gamemode/files had an _C at the end.

4 Likes

“What if you want to use the same level with multiple game modes?”

Has this question ever been answered? I too need to know that!

Hi, yes, I answered this a few months ago when I came across the same wall. I used the Open Level node (upon clicking on a menu button for a certain mode) to load the desired level and added this as a parameter in the options input of the node. You would change ThirdPersonGameMode.ThirdPersonGameMode_C to whichever game mode you want. Keep in mind to add the _C to the end, even if you don’t see that in the name of your game mode in the file explorer.

?Game=/Game/Player/Blueprints/ThirdPersonGameMode.ThirdPersonGameMode_C

1 Like

Hi. This work for me too, also using de “_C” at the end of the reference. I dont know if this is a “standar feature” of UE4, it seems more like a hack, but it works.
Anyway, you always have the alternative of using an empty persistent Level with the GameMode and a sub-level that will be the reusable map.

It worked great in editor, but in packaged build gamemode was not loaded, logs stated:

LogLoad: Warning: Failed to load game mode …

LogStreaming: Error: Couldn’t find
file for package…

This means gamemode is not packaged into build. To prevent this issue one must reference gamemode somewhere. Or easier is to open project settings: Project - Packaging, Additional Asset Directories to Cook and add folder of your missing game mode (for example: “/Game/Player/Blueprints”)
Hope this helps someone in future.

5 Likes

Any idea why this doesn’t work for me? It works in editor, and stand alone, but when I package it doesn’t work. I’ve added a map to be included with the package that uses the new game mode as well so that the package includes it. Nothing seems to be working. I’ve also done the “additional Asset Directories to Cook” thing, and also made sure everything was fixed up in redirectors. It’s driving me nuts!

No Idea. However i suggest checking out packaged build files.
Download software named: “UE Viewer”

Try opening your packaged build and see if game mode is packaged in game files.

Also if you don’t want to use “UE Viewer” i think there is option to package all game files seperately, not in big .pak files? I’m not sure about this, but you maybe it helps you to see if game mode is in packaged build or not.

If game mode is in files… then something else is wrong. Log files don’t write any useful info about it, right? Maybe someone else will be able to help.

For anyone else having difficulty with this, this page explains how to override the game mode based on the map/level. Setting Up a Game Mode | Unreal Engine Documentation