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"

C++ callback when game starts

I am trying to setup a callback that is called when the game starts. I tried several spots:

  • GameMode constructor

  • StartupModule method of the GameModule.

The code in both locations is called when the editor is started, so I guess that's ok. However, when I hit the play button in the editor to start the actual game none of these is called.

Is there a way to receive a callback at that particular time ?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 17 '16 at 03:02 PM in C++ Programming

avatar image

je42
3 1 1 5

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

1 answer: sort voted first

Hi,

You can override the PostLogin function in your GameMode.

 /** Called after a successful login.  This is the first place it is safe to call replicated functions on the PlayerAController. */
 virtual void PostLogin( APlayerController* NewPlayer );

For Example:

 void AMyGameMode::PostLogin(APlayerController* NewPlayer)
 {
     Super::PostLogin(NewPlayer);
 
     //... do something. Here, if you want, you can loop over all the player controllers to notify all player that a new player is entering...
 }

Best regards

more ▼

answered Jan 17 '16 at 03:47 PM

avatar image

nan2cc
502 23 13 38

avatar image TTaM Jan 17 '16 at 04:36 PM

If it's a multiplayer game, that will run every time somebody logs in and on a dedicated server possibly never.

The better way is to override HandleMatchIsWaitingToStart() in the game mode. It will be called only once when the map loads.

avatar image nan2cc Jan 17 '16 at 04:50 PM

Hi TTaM,

Yeah, you are right, this kind of things depend of what do you need. The HandleMatchIsWaitingToStart is another good place, but what happen if someone login with the match in progress ? I don't know if in that case HandleMatchIsWaitingToStart is called. In this situation one option is, inside the PostLogin:

 if (PC && IsMatchInProgress())
 {
     //do something with this new player
 } 

And yeah, its true. This PostLogin function will run every time somebody logs in. But from parameter you have the specific new player controller, so you can do whatever you want just with this player controller. And also, you have the oportunity to notify another users.

Basically its depend of your needs, probably for je42 its better to use HandleMatchIsWaitingToStart.

Cheers

(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