Is it possible to turn parent class's Replicated variable into OnRepNotify from child class?

This should be possible through the reflection system. It’s just going to take some digging through the engine source code and might be more effort than it’s worth. The code below is how you might go about it.


UClass* reflectionClass = ALobbyBeaconClient::StaticClass();
FProperty* currentProperty  = reflectionClass->PropertyLink;

while(currentProperty){

    if(currentProperty->GetNameCPP().Equals(FString("LobbyState"))){
        currentProperty->SetPropetryFlags(EPropertyFlags::CPF_RepNotify);
        currentProperty->RepNotifyFunc = FName("OnRep_SomeFunction");
        //Any other logic that alters the underlyng property and its replication to use the function
    }

    currentProperty = currentProperty->PropertyLinkNext;
}

Please note that I have not tested the code above. Setting the notify may require applying the repnotify flag on the variables corresponding property. A major potential problem with doing this might be on how it determines the function to use. I’m assuming it uses the RepNotifyFunc variable to find the function to use on replication. If the function must exist within the ALobbyBeaconClient class, then this won’t work at all since you cannot add the function to the base class. If the function is checked to exist on the derived class then this should work. There’s probably other nuances with the reflection system and replication that I’m missing, but you’re going to need to figure those out. Hopefully someone else with more knowledge on the reflection system aspect of relication can chime in.

2 Likes