Replicating Structs with Properties

Let’s say I have a struct, something like …

USTRUCT(BlueprintType)
struct FProperties
{
    GENERATED_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    bool EverythingIsFine;
    
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    int32 Score;
}

And it’s replicated in an Actor …

UCLASS()
class NT2_API MyPerfectActor : public AActor
{
    GENERATED_BODY()

    virtual void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const override;

    UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite)
    FProperties Props;

    ...
}

I then change either the bool or int32 in Props. Will the whole Struct be sent over the wire, or just the variable that changed?

Just the value that changed. Structs are “Unfolded” into their component properties when they are members of Actors/Components, so I believe you also won’t pay any additional cost for property headers (need to vet this, but 90% certain).

Structs contained in TArray will also only send their changes, not the full struct. The property “headers” (i.e, the part of the packet that identifies the property being changed) will be larger though, as it needs to identify the array property, the index of the array, and the internal struct property, but this is usually nothing to worry about.

Keep in mind that because USTRUCT() use this “delta replication” and do not replicate atomically, there’s a chance that a struct can be in a state client-side that never existed on the Server if you change individual properties between network frames (but this is no different to other actor properties).

1 Like