Replicated actor passed to a multicast RPC function is null on clients

The actor probably hasn’t fully replicated yet, until it does the client won’t have created it and the engine won’t be able to turn the network ID into a valid pointer. Additionally, the actor may not even be relevant for some clients.

You can’t spawn something then immediately call an RPC related to it as you have no control over which will arrive first - and this behaviour can be pretty random each time. Some people would encourage using a delay, but that an awful bug-prone solution to something that honestly just needs a slight redesign.

Depending on what you need to do, I would just override the BeginPlay() function of the spawned item and perform whatever setup you need to right there. That way you have no race conditions and as a bonus, you avoid the overhead of a multicast altogether. As soon as the item arrives on each client, they will perform whatever setup they need to.

10 Likes