Replicate UObjects

Hey everyone,

Currently I’m developing an RTS-inventory-system and want to replicate it now.

Basically, I have an ActorComponent (UInventory) that owns UObjects (UInventorySlot). Those Inventoryslots control the current storage and max storage of the current item and own another UObject(UInventoryItem), which contains Metadata.

I can’t replicate the UObjects. I actually don’t want to use a AActor or AInfo, because these classes have many unnecessary functionality and I don’t think that an ActorComponent owning Actors is a good thing.

So how do I replicate this, is there a good documentation/tutorial on how you can replicate UObjects or do I have to use AActor/AInfo for this?

Or is my approach generally not good and I should do this completely different?

Thanks in advance!

Hi KanakemitHacke

It is true, classes like Actors contain vast amounts of functionality when in reality we only want to use 1/3 of it. However, within all that functionality is the logic behind replication. It is not something that is simple to reproduce at all and will probably be very time consuming.

I highly doubt there is any decent documentation out there for how actors replicate. I guess you would have to open up the actor class from the source and attempt to extract the replication logic.

However, I would suggest you save yourself alot of headaches and just use the actor class :wink:

Good luck

Alex

Thanks a lot!

From what I have read the actors shouldn’t affect the performance significantly anyways, since I don’t need a static mesh or tick on them.

Old thread but I was able to replicate UObjects by overriding ReplicateSubobjects on the owning UActorComponent and manually replicating the array of UObjects, which in your case would be your UInventorySlot. And on the UObject you need to override IsSupportedForNetworking to return true.

bool UActorComponent::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
{
bool bWroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);

for(UObject* Object : ObjectArray)
	bWroteSomething |= Channel->ReplicateSubobject(Object, *Bunch, *RepFlags);

return bWroteSomething;

}

bool UObject::IsSupportedForNetworking() const
{
return true;
}

Old thread but I was able to replicate UObjects by overriding ReplicateSubobjects on the owning UActorComponent and manually replicating the array of UObjects, which in your case would be your UInventorySlot. And on the UObject you need to override IsSupportedForNetworking to return true.

bool UActorComponent::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
{
bool bWroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);

for(UObject* Object : ObjectArray)
	bWroteSomething |= Channel->ReplicateSubobject(Object, *Bunch, *RepFlags);

return bWroteSomething;

}

bool UObject::IsSupportedForNetworking() const
{
return true;
}