Getting notified when a custom component has a change in replicated values

I have a simple custom component containing a pair of integer values. The component is tagged as replicated. I would like to know on the client when the client gets an update to one of the component variables from the server. Is there a way to do this?

The ‘Component’ won’t replicate as an entire object, but values that you specify to replicate specifically will. So long as Actor Components have an owning Actor, they will replicate their marked properties as part of that actor. You set it up the same way as Actors:

MyActorComponent.h



UPROPERTY(ReplicatedUsing = "OnRep_MyVariable")
int32 SomeReplicatedVar;

UFUNCTION()
void OnRep_MyVariable();


MyActorComponent.cpp



void UMyActorComponent::OnRep_MyVariable()
{
    // Do something when variable replicates from the server and is different to the local value
}

void UMyActorComponent::GetLifetimeReplicatedProps(const OutProps)
{
    DOREPLIFETIME(UMyActorComponent, SomeReplicatedVar);
}


Syntax isn’t 100% correct, doing the last part from memory…