Download

Use default object of UObject for property replication

I inherited many of my objects like weapon, character, ability etc. from UObject.
They all have some logic which is only necessary on the server, the clients just needs to know about the default values, I’ve set up in the contructor or the editor.

So is it possible to **stop the replication from creating a new instance **and using the classes default object instead?

Currently I’m just overwriting the value on the clients with the classes default value after replication:



void UCharacterComponent::OnCharacterReplicated()
{
    if (GetNetMode() != ENetMode::NM_ListenServer)
        Character = Cast<UCharacterBase>(Character->GetClass()->GetDefaultObject());
}


this way the created instance should be destroyed by the garbage collector and always only the default object exists on clients.