Correct way to wait replication of an Actor ? *solved*

So,

Imagine i’ve got a Weapon, Actor, replicated.
I want to spawn it, then play with him (give him to a player for example).

In a perfect world, i will spawn him, and give by the constructor to who i want to give the weapon, and i will manage this inside weapon.

But imagine, for design reason, i want to manage him from my pawn.
Like : Server spawn the weapon > Server call a RPC Multicast inside my pawn to pick the item.

In this specifique case, it will fail, cause the RPC will be executed most of the time by the clients, before the spawn of the weapon is effective on them.
So, for this kind of case, how we should / want handle it ? or it’s bad at the point we should never manage thing like this.

1 Like

Interessing discussion w/ @FooKing on discord :

A simple loop with == null should do the trick.

Hey I’ve ran into the same issue

A simple loop with == null should do the trick.

care to elaborate on this?

It’s a bit old.

In my memory, you just try to pick it until it spawn (like every tick).

But ofc, this is an horrible design, and should not be handled like this.

The weapon should be a replicated property of the player who is equipping it. You then use an OnRep callback to handle the equip logic client-side, you don’t send Multicasts.

Stateful/Persistent changes should always be handled by replicated properties, never multicasts. RPC’s are for one-shot events only.

1 Like