Is there a need for game mode for a single player game?

I was reading the documentation for Game Modes and I understand that it is essential for multiplayer games. My question is whether it has it’s uses in single player titles?

Gamemode is very useful to implement general gameplay functions and store common values that can be easily shared with other blueprints via ‘get gamemode’. I can’t imagine a full game without a gamemode on it :slight_smile:

4 Likes

So if I have some value that I want to be global for the level/game I would store it into the gamemode?

Yes sort of :slight_smile: there are a lot of ways to communicate things.
You have global access on any casted blueprint.

For example you can have stuff on gamemode (variables,functions) and call from any other blueprint with getGamemode–>castto(thegamemodeclass)–>getvariable/runFunction
but you can do the same with a player blueprint or a gameInstance blueprint (gameinstance values persists even if you open a new level at runtime, gamemode, player controller and others dont). Let me put you an example:

i have this 3 blueprints:

image

a gamemode a player controller and a game instance.

You set those in world settings. Overriding gamemode will allow you to change
also your default player controller right there:
image

in the case of gameInstance you must set that on settings:

ok now lets add some stuff on those 3:

gamemode:

image

player controller:

image

game instance:
image

now lets call those from any other blueprint:

gett call stuff from gamemode:

from player controller:

from game instance:

its very important to CAST. Casting ‘unlocks/grants’ access inside the blueprints.

if you want to use for example some stuff from gamemode in a blueprint very often
is suggested to get/cast/store a gamemode instance in a variable for later usage like this:

here you can see I cast gamemode only once and then I store it in a variable…later I can access gamemode just by reading that variable because it is your gamemode class already and was filled with the actual gamemode on beginplay.

Hope it helps understand better. There are not global stuff…you can make those ‘global’ by getting/casting it :slight_smile:

Best,
Dany

2 Likes

I have only made single player games.

I have used game mode just for an easy access general manager. But the player controller could just as well be used in the same way. That’s what I am doing in current project.

The key thing to know is lifetime. Game mode lives and dies with level. Player controller is persistent. So if you were handling input or something that needs to span levels, be aware of that.

In general, for single player solo developed projects, I’ve found it preferable to use fewer classes. Basically don’t split stuff up until its really necessary. Otherwise you just introduce complexity for no benefit. Virtually all bugs will be a problem of communications, so you can gain a ton of speed to wipe that out, then can refactor later if things are getting unruly.

2 Likes

Thank you all for the explanation. I’m new to unreal, so it’s great to have someone explain these concepts to me.

1 Like

Player controller dont persists on new opened map.

Gameinstance does.

1 Like