Replicated TArray's RepNotify is premature

TArray size of the client will be synchronized first and RepNotify will be triggered (the label “REPNOTIFY” in the figure shows that the last element in the array is nullptr, what i want is trigger RepNotify after the element is completely synchronized).

It is obvious from the picture that the BeginPlay of array elements is later than RepNotify, so how can I get the correct TArray element object pointer in RepNotify?

The Player State may replicate before the actor it’s referencing, so it’s changes will be applied first. This may happen in the same frame or accross many frames, but the order is arbitrary and cannot be relied on anyway so expecting it to be present in that array when the weapon calls “BeginPlay” is not going to be safe.

IMO, this particular case has code smell - you’re relying on the Player State actor to initialize the weapon. These types are totally unrelated and shouldn’t be dependent on each other to function.

1 Like