Download

Why are variables that are exposed on spawn not replicating?

Variables that are set on spawn are working on the server, but are not replicated on the clients. Is this supposed to happen?

I may not know your setup so you may already have this, but try using a “Switch, has authority” instead of your branch and “is server function”. (If you do this for a reason, ignore this.) I assume you already have your weapon type var set to replicate and the server should be replicating this. If youre not running on a dedicated server, this may actually not be replicating to the server side of the client/server combo you are running, and the authority check should fix that issue. Unreal can be a little wonky with its networking sometimes.

thanks for the response,
When I set the “Weapon Type” to replicate, it replicates in the event graph but is null during the construction script. I can move my code in the event graph but it would be much cleaner if variables where there from the first frame.

Variables are only considered for rep when changed. So Its probably never considered changed when set on spawn

Is Weapon Type a String? You may need to set it on Event Begin Play instead of On Construct.

Confirming here if anyone else comes across this, it doesn’t look like the spawn variables are replicated to the clients in time for On Construct to see them like Dedrick said. So definitely put things relying on the On Spawn variables in BeginPlay. If you need On Construct for editor or other reasons, just make a function and call it in both places.

Thank you. I can also confirm this. Replication is not on time for construction script, it is for begin play.