I’m trying to implement a multiplayer inventory. I got a blutprint interface BP_Lootable which is implemented by my items and my inventory consists of an array of BP_Lootables. However, I cannot manage to replicate this array. On the server it works fine but when I loot an item with the client it is not added to the inventory array.
The Blueprint Interface documentation (Blueprint Interface | Unreal Engine Documentation) states:
You can use the Replicates checkbox for any Interfaces containing functions that need to replicate across the server. This is found within the Details tab by first clicking the Class Settings button.
I cannot find this option anywhere in the interface. So my questions are:
- Can interfaces even be replicated?
- Is the documentation up to date (it says 4.9)?
- Is this a bug and the option should actually be present?
- Is there a workaround to achieve this?
Hi, as for 1. - 3. I didn’t see any replicates checkbox on interfaces in 4.26
As for 4. just do it like you would replicate anything else from client to server, so with a RunOnServer event (you can’t use this in the items though since only the owning client can call RunOnServer events, so you will need to put this inside the possessed pawn or the player controller, or even better just send the player input to the server and let the server handle everything else).
I’m new to networking but as far as I understand I’m already doing this:
The interact inputAction calls the interact event on the server and the item adds itself to the inventory.
I could verify that this works on the server but not on the client. The inventory array is always empty on the client.
I could verify that this works on the
server but not on the client. The
inventory array is always empty on the
You also need to tell the client/s about this. So you could mark the whole inventory array replicated but since that array may be rather large it may be better to use a Multicast/RunOnOwningClient to tell the clients to add an item to the array. So not replicating the whole array, but only the changes.
Also if your ItemData is an UObject, then AFAIK those don’t replicate by default and you can’t send them via RPCs (RunOnServer, Multicast, RunOnOwningClient).
Also if your ItemData is an UObject, then AFAIK those don’t replicate bydefault and you can’t send them via RPCs (RunOnServer, Multicast,RunOnOwningClient).
This is good to know, They are indeed just UObjects that implement the interface. The idea was to just store the item data in the inventory instead of the whole actor. As you said the inventory can possibly store lots of items and I wanted to reduce the overhead. (I also had the issue to switch the owner of the ItemData from ItemActor to the InventoryComponent, which is apparently not possible in blueprint. But thats a different issue)
I already marked all fields of the inventory (except UI) as replicated so this should not be the issue then. If I understand you correctly I need to implement the network replication feature myself for the ItemData UObject right?
I don’t know how to make an UObject replicate, I never tried that. But if you’re just storing the data you could try to use structs instead, those should replicate.
We’ve made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.
Structs is for my case no satisfying solution as it does not allow for inheritance in blueprints. I researched UObject replication and found some posts how to do it. Currently I implemented a new C++ class and set it as my parent/super class for ItemData:
UCLASS(Blueprintable, BlueprintType, Abstract, meta=(ShortTooltip="Allows replication of plain UObjects."))
class INVENTORYFRAMEWORK_API UNetworkObject : public UObject
virtual bool IsSupportedForNetworking() const override;
bool UNetworkObject::IsSupportedForNetworking() const
Didn’t work yet but I think I’m on the right track. I will update and post the solution if I manage to fix this.