Hey,
i have a problem with an RPC that goes from Client to Server.
I have a replicated ActorComponent that serves as an Inventory for several Actors in my Game.
For now, my PlayerState has one and a chest has one.
Inside of the ActorComponent, i have a replicated Array and Client to Server RPCs that are called
from the Client inside of a UMG widget. So if he drags an Item from one Slot to another, he asks
the Server to do this for him.
This works for the PlayerState Component, but not for the Chest. The Chest is calling the function,
but not the Client to Server RPC.
So i learned that a client needs to be the NetOwner of an Actor to be allowed to call RPCs from Client
to Server on it. The Chest is placed in the Scene and not spawned. Also serveral players at once can
look into the chest and use it. Even if i set the NetOwner of the Chest to the PlayerController of the
using Player, the Chest wouldn’t work for the others, would it?
I could set the owner each time a Player is swapping an item around, but i don’t think this is correct.
HOW can i manage this? All the inventory related functions are in my component. Would i need to have
functions in my Controller to get access to the Chest functions? Like passing all the data, that
i would pass to the RPC directly, to an RPC in the Controller that then calls the function in the Chest Component?
I’m not that good in NetOwner things, so i would be happy about help here ):
EDIT:
Ok, so i made an RPC in my Controller, doing the following:
void AUnknownProjectPlayerController::ServerPC_MoveItemToInventorySlot_Implementation(UInventoryComponent* _TargetInvCom, int32 _TargetSlot, UInventoryComponent* _SourceInvCom, int32 _SourceSlot)
{
if (_TargetInvCom)
{
_TargetInvCom->MoveItemToInventorySlot(_TargetSlot, _SourceInvCom, _SourceSlot);
}
}
And this gets called in the Component, instead of the replicated function that i would ran there (which does the same).
Is this a legal way to do so?