I’m running into an issue where an actor reference I have on the client turns to null when passed to a Server RPC.
Essentially building an Inventory system, where if a player interacts with a container, a Widget showing the items pops up. The player can then transfer items over to their inventory widget.
The container is not NetOwned by the player. I managed to circumvent that by calling the Transfer Item Server RPC on the player character taking Container reference.
The issue is that when OnDrop executes and forwards the necessary data to the Server RPC, the Container ref is null on the server side.
I can tell that the ref is correct on the Client side, but null on the server based off the Print Strings. I’ve been scratching my head at this one. When looking at the Network properties of the Item container, everything look right:
UE actually resolves the Objects/Actors GUID and sends that over the network when sending an object reference.
Once the RPC arrives, the engine resolves that GUID back to the actual reference.
Meaning you can only pass in replicated objects that exist on both client and server.
Note that this also only works if the owner of the object/component is replicated as well.
E.g. sending the reference of a non-replicated component that lives on a replicated actor will fail.
Both need to replicate for it to work.
It was weird how Inventory Component didn’t show the white dots. I double-checked it has Component replicates and SetIsReplicatedByDefault(true).
I now have the following in the Inventory Component’s Constructor:
SetIsReplicatedByDefault(true);
SetIsReplicated(true); // White dots appeared after I added this?
and the white dots appear. During run-time I debugged that both actors replicated and their respective Inventory Components.
I also used this function to check NetGUID (although I’m not too familiar with that). This fired at the Container’s BeginPlay and during On Drop from the client side.
At the time of the transfer, the NetGUID of the Inventory Container matched (32). Strangely enough, At BP Begin Play, the Container had a NetGUID of 0. I guess NetGUID are assigned after BP Begin Play on the actors? (Like I said, I don’t know much about them).
The issue was that I was using a TSoftObjectPtr<AActor> Interactable to hold the reference to the Item Container. Then off this pointer, I build the Inventory Widgets and through them passed the necessary data for the Drag Drop Operation.
A google search showed that Soft Pointers don’t replicate, even if they are marked to. I changed it to a hard pointer and everything worked.