Game Mode in Mobile Game (iOS or Android)

I’m quite confused and can’t find the answer anywhere. Sure I know that game mode only exist in server. But that’s when you deploy the game as server right? What if you package (deploy) the game as a single standalone single-player mobile application?

Will there be any instance of game mode in that game? Can it be accessed via this command?


The GameMode is spawned based on the game type. That isn’t determined during packaging but rather at run time. So you can package a “client” and still run it as a standalone. In that case it will get a GameMode.

And yes, if the GameMode is of the class you are casting to then you should get a good pointer.

One other thing: I’ve never packaged specifically for client. I build a regular game and connect it to my server. I don’t even know why the client build is needed. So if you build for that it may not get a game mode at all, I’m not sure. I was saying that a regular build will act both as a client and standalone as you require from the same packaged game.

Thank you for responding. I know that UE4 uses Client-Server concept. It means there’s an application instance on the client side (smartphone, PC, laptop, xbox, PS4, etc) and there’s an application instance on the server side (machine on datacenter). I just can’t find any reference of how, deployed application with UE4, know that it is supposed to function as “client” or as “server”.

Because if someone want to develop a simple game like Clash of Clans, UE4’s network architecture is far too sophisticated. He can just create a standalone single-player game which will connect to remote server via simple socket programming, because the game does not require real-time synchronization with server during base invasion.

So my concern is, if I do it this way, will UE4 able to instantiate AGameModeBase on the mobile game?
Are there specific setting to determine that the compilation (package) should function as client or server?

OK so your game code needs to handle both cases. There are special C++ functions and blueprint nodes that tell you what the situation is. For example, “HasAuthority”. There is a node that you call (Switch Has Authority) and it has two output execution pins. One will be executed on the server and one will be executed on the client. The server is the “authority” so it should be the one changing replicated variables. The client is the “remote” so it should be reading those values as well as calling any replicated functions to tell the server to instigate desired functionality.

When you run a local standalone game, any time you ask about authority, it will say that you have it. So for the switch node, it will always execute the “authority” pin. And the same functionality that the server will run will also be run in a standalone situation.

The engine knows which role to report because either it’s a server executable (authority), it’s a game build and is not connected to a server (also authority), or it’s a game build and is connected to a server (remote).

Hope that helps.

It helps a little bit. Perhaps it’s because I never used that node before.

So assuming that I have a custom game mode called AMyGameMode, derived from AGameModeBase, every time I call GetWorld()->GetAuthGameMode<AMyGameMode>() inside an actor inside my mobile game, will it always return the expected object instance or NULL?

For a standalone game and the server, that is correct. And you should only get NULL if there is something wrong or if you’re connected to a server. You also need to tell the level which GameMode class to use so don’t forget to do that or it will spawn a regular GameModeBase…