I have an TArray of a custom struct FNiagaraMovementData
that is replicated in Unreal Engine, but the struct’s member variables are not marked as replicated. Here is the struct definition:
USTRUCT()
struct FNiagaraMovementData
{
GENERATED_BODY()
UPROPERTY()
TObjectPtr<UNiagaraComponent> NiagaraComponent;
FVector ForwardDirection;
};
For proper replication, do I need to mark the properties inside the struct with UPROPERTY(Replicated)
? If so, how should I handle replication for properties like TObjectPtr? Should I use an identifier or another method for replication, and how do I set up GetLifetimeReplicatedProps
to include these properties?
Current Situation:
The client that spawned the actor (using Client Prediction) can correctly access and use the FNiagaraMovementData
array (which is functioning as expected).
The server, which maintains its own copy of this array, is able to access it as well.
However, when I attempt to use a Net Multicast from the server to update all clients, the array of structs appears to be empty on the clients. This indicates that the replication is not working as intended.
This is my setup:
//.h
UPROPERTY(Replicated)
TArray<FNiagaraMovementData> ActiveNiagaraComponentsServerSide;
//.cpp
Tick(){
if (!HasAuthority())
{
// Client Prediction of the NiagaraComponents (using a separate array)
}
else
{
// Move all NiagaraComponents in 3D World, from the Server Array
// Multicast to be able to Move each NiagaraComponents from each ServerArray that should be replicated to every single client in the game (which seems to not be working at the moment.. since 1 of his value is just empty)
}
}
When logging and printing the vector stored inside the struct in the multicast (so on all clients):
Niagara Forward Direction:
(actually empty all the time)
This is my Multicast if you were curious:
UFUNCTION(NetMulticast, Reliable)
void MulticastMoveNiagaraParticles(float DeltaTime);
And yes, the function definition has the _Implementation.
PS*
If you think something isn’t clear enough, don’t be shy to ask! Thanks a lot for any help!!