Is beginplay called on a simulated proxy and when?
This is a noob question , mostly because I'm too lazy to test or might miss some certain exception scenarios in the test.
So when a a players joins a match in progress all the other pawns would generally spawn on this end as a simulated proxy. Now here would BeginPlay would be called on those simulated proxies for the new player?
Or is begin play called only when GameBegins or when an actor is spawned from game logic instead of replication?
I know OnConstruction is called on all role versions of all actors, but does begin play?
asked Dec 18 '16 at 09:12 PM in Using UE4
See my detailed answer below. I know I could have left a one liner answer, but I don't want you to spend hours and days figuring out the execution order, execution timing and replication like I did.
ConstructionScript is called on both Authority and non-authority clients when an object is spawned. This executes before BeginPlay which makes it the ideal place to do "bootstrap" / "initialization" that is required before BeginPlay, like set materials, meshes and perform line traces, etc.
BeginPlay is called on Authority and non-authority clients after an object is spawned and placed in the world. This is called after ConstructionScript. If a player joins a game late, their pawn will still have the ConstructionScript method and BeginPlay events fired on both Authority and non-authority clients.
From my own experience: You can rely on ConstructionScript always being called before BeginPlay. But do NOT rely on the Authority BeginPlay to finish it's execution before the non-authority client's BeginPlay. If you set a replicated variable in the Authority's BeginPlay do not rely on that variable being replicated and available for use by the time the non-authority client executes it's BeginPlay. If you need your Authority to set a variable in BeginPlay and replicate that variable to the client so the client can use it in it's own BeginPlay, you should create a custom (Reliable) Run on Owning Client event called "BootstrapClient" and call that event on the Authority's BeginPlay to tell your client it can bootstrap safely.
answered Dec 18 '16 at 09:49 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here