Question about replicated and ownership

Hello again!

So I am currently having an issue with the Run on Server RPC and ownership. I was hoping someone could explain what the heck is going on or what I am doing wrong. I took time to study the Compendium created by Cedric (that thing is actually gold) before coming here but not sure what I am doing wrong.

From my understanding the RoS RPC will not run unless it is owned by either the player pawn or player controller. I have a weapon class that has a event called “Unequip Weapon”. If I call that event from the class itself the weapon is not destroyed but if I call the same event from the Player Character it works as intended.

Event Server spawn weapon - called from inventory comp on player character

Event on Use - Called from Weapon class

Event equip weapon - Called from Weapon class

Event Unequip Weapon - Called from Weapon class

Event Destroy Item - Called from Weapon parent class
image

Unequip Test - Called from Player Character

Weapon isn’t destroy when calling unequip from the weapon itself but works when pressing G key.

1 Like

Personally I would not put the burden of equipping/ unequipping on any of the items.
Delegate this task to an actor component that manages equipment in your character.
That way it’s owned by the player and it is responsible for the actions regarding items on the character.

It also keeps your items clean of extra code that is not needed. Think in the long run 1 component code vs all items code.

Calling the equipment component on the character from your player controller is the best bet for it to not have problems with ownership.

1 Like

Thank you very much! I guess I was attempting to go about it all wrong. I created a new actor component that handles equipment just like you said and was able to getting it working pretty quickly.

Equipment Comp

Weapon Base

Result - no issues with multiplayer or replication

2 Likes

@Chitolocz Congratulations of getting it up and running :slight_smile:
Best of luck on your project. Hope you have a smooth dev experience.

You could consider adding a check function before equip if the character meets the needed requirements (if you have any rpg elements in your game).

2 Likes