I’m using structures for an inventory system, but you can’t pass a structure by pointer. This means I can’t have an array of derived structures as the inventory because, well, structures can only be passed by value (unless you don’t use the UPROPERTY marco, which I need for replication).
Because of this, I created uobject wrapper classes for the structures which can be passed by pointer. But I know uobjects aren’t automatically set up for replication.
This is what my uobject looks like:
UCLASS(BlueprintType)
class UItem : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated)
FItemStruct Item;
};
How do I set up replication for my wrapper class so my structure is flagged for replication? If it matters, besides the structure and uobject definitions, all other development will be done in blueprints (unless I run into more functionality problems in BPs).
I’m not asking what type of class to use. I’ve already chosen a uobject. I need to know how to set up replication for one because, from what I’ve found, documentation on adding replication to a uobject does not exist. Thanks.
Thanks for the help! I think I implemented IsSupportedForNetworking and GetLifetimeReplicatedProps properly, but when I try to override ReplicatedSubobjects I get an error saying, “method with override specifier ‘override’ did not override any base class methods”.
edit: It seems here that the method ReplicateSubobjects exists in AActor. Did you mean to override a different method?
edit 2: So it seems like you don’t use the override keyword because its the first declaration of the method. But now I don’t know what to put in the function to replicate the item structure.
Oh sorry, ReplicateSubobjects not must be overriden in UItem.
In best case you must inherit your object from AActor (AItem), not from UObject ( link ).
After that your instance will be network supported ( use DOREPLIFETIME in AItem::GetLifetimeReplicatedProps and AYourGameState::GetLifetimeReplicatedProps for your AItem array ).
Also you must set the variable bReplicates = true; in AItem constructor.
It seems here they replicated uobjects - you just need to manually do it. I really want to use uobjects instead of actors in this case. So I need to find out what to put in ReplicateSubobjects to replicate a structure.
That code would be in my uobject, right? If so, the uobject only has 1 item structure in it. Item is not an array. My uobject is a wrapper class for one struct. My array of items will be in an actor component.
When I try to do "bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
" it says, “UObject has no member ReplicateSubobjects.”
How would I do that in blueprints? My UItem is in C++ but my actor component, which is the actual inventory system, is written in blueprints.
And by ‘owner’ does that mean whatever reference I put into the “outer” pin in the node Construct Item? So in the picture below the owner of the item would be my inventory system actor component?