x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

 GetWorld()->GetAuthGameMode<AMyGameMode>()

Product Version: UE 4.16
Tags:
more ▼

asked Dec 08 '17 at 12:09 PM in C++ Programming

avatar image

Pelangi
266 22 34 42

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Dec 08 '17 at 02:18 PM

avatar image

Jin_VE
4.4k 32 79 42

avatar image Jin_VE Dec 08 '17 at 02:25 PM

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.

avatar image Pelangi Dec 09 '17 at 01:33 AM

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?

avatar image Jin_VE Dec 09 '17 at 01:44 AM

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.

avatar image Pelangi Dec 09 '17 at 09:57 AM

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?

avatar image Jin_VE Dec 09 '17 at 10:03 AM

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..

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question