Why TArray is not replicating?

In my game, Character has a set of spells which I used a Tarray to store it and replicate it to all clients. And I did TArray replication just like the ShooterGame. But the TArray member only replicates the size of the array, excluding the spells.

Below is my C++ code:

26726-definition.png

26728-spawn.jpg

After spawning all the spell, in client side, I found that the SpellArray.Num() is correct, but SpellArray[i] == NULL.
Help!! what’s happening??

And After reading some similiar question on AnswerHud, I found someone solved it by “spell->SetReplicates(true);” after spawn the spell. But in my case, it still doesn’t work!

Hey, Duncan. I did put
“bReplicates = true;
bReplicateInstigator = true;”

in the construction script of ALabSpell.

try to put bReplicates = true; in initialize of ALabSpell, your should be in ALabSpell::ALabSpell(const class FObjectInitializer& PCIP) : Super(PCIP)

ok, it should have work, we use same thing for our weapons, but we call AddUnique and then SetOwner for the weapon to the Pawn.

After setting SetOwner , it worked~

Sorry to revive this old thread, but I’m facing a very similar issue - I’m spawning some Actors on the server, adding them to a replicated TArray, but I only end up with a (correctly sized) TArray full of NULLs on the client.

I’ve tried all the stuff mentioned here, including SetOwner(), bReplicates = true and actor->SetReplicates(true), but nothing works.

One difference, though, is that this TArray resides on my AGameState implementation (instead of, let’s say, a replicated in-game character). Would this be an issue? Mind you, every other replicated variable in my AGameState replicates correctly - it’s just this TArray that’s misbehaving;

Thanks in advance for any help. Cheers!

Solved it. What I forgot was that my replicated Actors in the TArray also have associated Blueprints. They started replicating correctly after I ticked the “Always Relevant” checkbox.

I guess this was needed because this TArray is really being used as a data container (spawned at origin and never moved, with the GameState as its owner instead of a Character/Pawn) and so was deemed as “not relevant” on the client.

How about you make function that runs on server, and call it? Replication works from server to clients, so any variable change must run on server.