Replicated TArray contains NULL

I am somewhat following the ShooterGame sample and am Replicating my spawned inventory to the owner only.

UPROPERTY(Transient, ReplicatedUsing = OnRep_Inventory)
TArray<class AWeapon*> Inventory;

With the following in ASoldier::GetLifetimeReplicatedProps

    DOREPLIFETIME_CONDITION(ASoldier, Inventory, COND_OwnerOnly);

Running with a dedicated server, I can see the OnRep_Inventory being called but he TArray, although apropriately sized, contains NULL.

Any hints would be appreciated.



I’m having a similar issue, did you find a solution to this?


Wow!! that did the trick

I deleted SetReplicates() some time ago and put only bReplicates=true since the engine was showing a warning telling that setting bReplicates directly was the correct procedure.

Thank you so much!

This particular problem has long been expunged from our code base but I for completeness sake I would say that SetReplicates(true) is not appropriate in the CTOR, bReplicates = true. I’ll trawl through our commmit logs and see If I can identify the solution we adopted.

My pleasure.

I will convert this as an answer please mark it :slight_smile:

Do you SetReplicates(true); in your Weapon class ?

Something weird happened before, but now it isn’t working, so last time I put SetReplicates(true) it worked by chance.
I tried several times and 90% of the times editor crashes (because I’m doing a for each loop on the TArray on the OnRep function and it finds a NULL pointer)

I had the same problem, finally i found out that when spawning object you need to set owner for proper replication

for example when spawned on Server:

FActorSpawnParameters SpawnParam;
SpawnParam.Owner = GetOwner();