Only replicate property on interaction

Say I have a chest full of items. I want the player to know where that chest is so it has to replicate its transform, but I don’t want them to know what’s in it until they interact with it. Is there a way to manually turn on and off replication of a particular property for a particular player? Do I have to resort to RPC’s?

I am not sure about particular properties but there is a function that allows you to control replication of whole actors: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/IsNetRelevantFor/1/index.html

Unless the chest has a network “Owner”, then you can’t control who it replicates to (at least, not easily anyway). With an Owner, you can use the COND_OwnerOnly flag (or COND_SkipOwner for the opposite effect).

To some extent, you can control when properties replicate by using the COND_Custom replication flag, and overriding PreReplication(). Here you can bypass property replication on a per-property basis in specific conditions using DOREPLIFETIME_ACTIVE_OVERRIDE. Unfortunately it’s not possible to use multiple flags on a single property.

I believe ACharacter does this with one or two of it’s properties if you need an example.

Here is an example code using DOREPLIFETIME_ACTIVE_OVERRIDE mentioned by @TheJamsh


void AYourActorClass::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);
    DOREPLIFETIME_CONDITION(AYourActorClass, MyIntVariable, COND_Custom);    
}

void AYourActorClass::PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker)
{
    Super::PreReplication(ChangedPropertyTracker);
    DOREPLIFETIME_ACTIVE_OVERRIDE(AYourActorClass, MyIntVariable, MyIntVariable > 0);
}

In the above code, MyIntVariable will only be replicated when its value is > 0.

Thanks, but that’s only one bit of it, the other is only replicating it to those that need to see it. Sending out the contents of a chest to all players on a server every time someone opens a box isn’t ideal. I think my only option may be RPC’s or a custom array implementation.

Relevancy handles if it gets sent or not. Just be aware that if you try to make a state change while a thing is not relevant you need to make sure it gets updated when it gets relevant or you will have a mismatch between clients.