Ok, I get it, Game Mode only exists on the server, so a client can not cast to one (and thus not access variables or functions). make sense.
What is killing me, is it seems the only OnPostLogin is in the game mode, so when a person connects (Multiplayer), it appears it should run that in the game mode, that’s fine. From that I want to pop up a menu (widget)… so I have a custom event made in my player controller, I cast to that and call that, and ahve it set to RELIABLE Replicated to Owning Client. Sounds find, sounds like it should work.
However, what happens is I host in one window… menu comes up, works, go into game fine. Then I open another window and connect to the host, it pops that menu up ON THE SERVER. How is that replicated to owning client?
This is driving me crazy.
All I am trying to do is when you enter a map, have it pull up a menu to select a character class. Works fine the way I had it IF the client connects in a predefined ‘pregame’ time that is counted down by a timer… if the state has already changed to ‘ingame’ though (this a variable that is replicated), no dice… it skips the onrep stuff I have for the state for ‘pregame’… as it should (duh)… so I tried to set the class selection to pop up via the Event OnPostLogin … but as I mentioned above, no dice.
LOL. Perhaps you can answer this one… I set event begin play to actually set the ‘currentgamestate’. It works, prints out the string I added to check.
What you do not see is at the beginning of ‘topregame’ it checks that variable, and I have a printstring there as well for testing, that prints out that we are NOT in ‘preGame’…
So how can ‘toPreGame’ be called BEFORE the stuff from Event Begin Play?
I put it there (to set current game state) just to try, no difference. Somehow the topregame is getting fired off before anything. The above image is the ONLY place it is called in the BP.
Which ofcourse first msg is at bottom, it prints that in ‘show selections’, so that is called before the stuff in BeginPlay somehow… then the red one is from topregame print string (i added append with CGS: in front just to make sure that was what I was seeing)… then the purple is from Event OnMatchState … after the first one, THEN the state get’s set to preGame …
added more print strings, one in the game state constructor, that fires early… the other in the Tick in the game state, to print out what the current game state is:
So while the game state is made, it appears perhaps the variables do not exist until after the match state hits ‘inprogress’ … good to know I guess… how to deal with it is a different question. Since clearly the OnPostLogin is useless as it fires before the rest of the system is ready.
Well, i set a boolean based on the return from OnSetMatchState … so it only is set to true once we get to ‘InProgress’… that and this hack and the OnPostLogin is delayed until things are actually running, so things work right (who knows what else I may find in all this in the morning since I am heading to bed)…
The real interesting thing to me though, is while OnPostLogin fires and things work right for now… once you hit the menu that pops up, and it clears… OnPostLogin is fired AGAIN… this is with one ‘player’, one window… so would be good to know what else fires that one…
I think tomorrow I want to throw together a blank project and just print from all the constructors and begin plays and such and actually record what order game instance, mode, state and player controller, character and state all fire off.
Well made a game mode, game instance, game state, controller, playerstate, pawn, hud… set them in the project defaults. All construction scripts run first.
Then the game mode onpostlogin runs (which still doesn’t make sense, as who logged in, or why before things are ready?
Then the match state goes to WaitingToStart (yeah, after onpostlogin)…
then pawn is constructed and possessed.
Then begin play for controller, pawn, hud, gm , gs, ps.
Then match state goes to InProgress
Then everything beings ticking, gm, gs, controller, ps, pawn, hud… in that order.
Interesting stuff, clearly one must build in a delay in onpostlogin (if you want to use it) to wait until you hit match state InProgress… and in the beginplays as well to ensure everything is properly initialized.
Now that I have that figured out and use the MatchState to drive things… I need to figure out how to have a loading screen show the whole time the map is loading… if you show one, then Open Level, or Join Session… once the new map loads it wipes out the widgets (or seems to), so you get a flash of the map… because the first MatchState the machine is running to catch is WaitingToStart… and if you pull up the loading screen elsewhere, that stuff isn’t loaded and ticking yet. hmm…
Loading Screen is not possible in the current versions of UE4 using BPs only. The widgets are killed when unloading the old map. ):
Also, the OnPostLogin is called for Client and Server. So when you start the Game, the Server is also calling “OnPostLogin” and will check the State.
By delaying it, you give the BeginPlay some time to call and then check the State.
You also need to remember, that data needs time to cross the Internet/LAN. If a client joins, the replicated value of your State isn’t directly there. It needs
a few seconds to get there. I have a project called “Ball Bump” on my free project thread that shows how to handle game states in multiplayer games.
Check my signature to see if you can learn something from it (:
For C++ you can check the ShooterGame. I have not looked into it for this myself, but people tell me to look into it when wanting a Loading Screen in C++.