Partial NetSerialization, Replicate Property without it Changing

Hey there.

So I’m trying to create a small Plugin that enables you to Replicate BLOBs of arbitrary size (for example textures). For that, I store my Data in a Struct that implements a custom NetSerialize function that will try to split up the stored data into manageable chunks.
Unfortunately, this function is only called once, as objects only try to replicate when some Property changed. But since the Data in the Struct does not change, this is not happening.

Here is a rough overview:

UCLASS(Blueprintable)
class ULargeReplicatedActorComponent : public UActorComponent {
    GENERATED_BODY()

public:
    UPROPERTY(Replicated)
    FLargeReplicatedObject Data;

    ULargeReplicatedActorComponent() {
        SetIsReplicatedByDefault(true);
        SetNetAddressable();
    }

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

        DOREPLIFETIME(ULargeReplicatedActorComponent, Data);
    }
};


USTRUCT()
struct FLargeReplicatedObject {
    GENERATED_BODY()

    // Stuff ....

    UPROPERTY()
    TArray<uint8> Data;

    bool NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess);

    // More Stuff ...
};


template<>
struct TStructOpsTypeTraits<FLargeReplicatedObject> : public TStructOpsTypeTraitsBase2<FLargeReplicatedObject> {
    enum {
        WithNetSerializer = true,
    };
};

I tried to give the FLargeReplicatedObject a COND_Custom and always calling DOREPLIFETIME_ACTIVE_OVERRIDE in PreReplication, but Unreal still ignored the Property.

Using the Push Model or ForceNetUpdate() also did not work.

If anyone has an idea, how I can force Unreal to replicate a Property, even though it has not changed, please let me know.

Thanks in Advance!

Ok, I found a workaround:

You can just give the Struct a new Property (e.g. a uint8) and increment this byte after each serialization. Unreal will then detect, that the Struct changed and call NetSerialize again.

private:
    UPROPERTY()
    uint8 RepKey = 0;

It’s not optimal, but it is only a byte, so who cares…

Once the structure has been replicated it will only replicate the changed elements. Thus the repkey if it’s the only thing that has changed.