Detect when GameState has replicated?
When a client first loads into a multiplayer game, some actors like GameState have not fully replicated yet. So if you try to access the PlayerArray in GameState on the client, you get access violation errors. So I'm wondering what is the best way to detect when the GameState has been fully replicated to the client? Ideally I'd like to have some event called so I can have the client's PlayerController respond, like update a UI for example. The only way I can think to do it is to have a check constantly running on Tick. I want to avoid doing that as I don't like using Tick and prefer to use an event driven approach.
asked Nov 18 '16 at 08:58 AM in Using UE4
Well, multiple ways I'd try to do this. First you can make a multicast GameState event "I'mHere", in which you can GetPlayerController(0) - CastTo(MyPlayerPC) and call "GStateIsHere" event, and do your thing.
Another idea is when the GameMode fires the OnPostLogin event, you call the RepToClient PlayerController event "ThisYouNeed", and pass the GameState's reference. If I guess well, the GameState already exists immediately on the client too, but its reference is not replicated to the client yet, that's why you get None.
Is it clear this way?
answered Nov 18 '16 at 12:31 PM
RepNotify is your friend here.
There are also several overrideable functions in GameStateBase that can be used to notify when replication has completed.
answered May 20 '19 at 02:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here