When you spawn a replicated actor on a server, it is my understanding that the creation of the actor on the client side will only have default values for that actor. It will not have the replicated variables the server has until after the actor is created.
I’ve been searching for the recommended way to handle a setup where you want to provide a spawning actor variables on creation. I’ve come up empty handed from official documentation and from years of people asking similar questions on these forums except someone suggesting the
Event BeginPlay is a good place.
What I’ve concluded investigating the code and playing with it:
Replicated vars provided at spawn* will not show up in the
Construction Scripton Blueprints for that replicated actor.
Replicated vars provided at spawn* will show up, even under large 1000ms+ latency and packet loss, after the
BeginPlayevent on Blueprints (and C++ code) for the replicated actor.
Alternatively, RepNotify setting on the var works as well. However, if your logic is “only on spawn”/trigger once - you need to guard against the value possibly changing in the future and retriggering logic. unless you set COND_Initial - I think that prevents it from replicating changes in the future correct?
Here’s an example scenario:
Server spawns a cube, but it has to tell the cube at spawn to be a specific color - ie blue or red.
The receiving player gets the cube spawned, but does not know its color during the
Any logic the cube needs that wants to know about the color var needs to happen after
Event BeginPlay if the logic is for only triggered once on spawn (eg play a spawn FX), and/or logic in ‘RepNotify’ if the cube needs to react to color ever possibly changing (eg change the color of the appearence)
Is this understanding correct? Are there better ways I have overlooked or misunderstood? I need to be able to provide a concrete method for non-programmers to be able to spawn replicated actors, with parameters, that won’t bite us later.
Event BeginPlay seems to be the hotness.
- Note: When I say “provided at spawn”, I mean in Blueprints the replicated variable has been flagged as “Expose on Spawn” so that when the Blueprint that spawns the replicated actor (eg our color cube), the variable is provided immediately on the spawn node (eg the color var).