Picking up items to separate hands

To check if you can carry stones you should add a CurrentInventory and a MaxInventory variable of type integer to your player (for me this is in ThirdPersonCharacter).

Why both? With MaxInventory you say “I can only carry 2 stones, not more”. Whenever you pick up a stone you increase your CurrentInventory by 1. So you can only pick up stones as long as CurrentInventory is less than MaxInventory.

When you want to carry your stones in your hands, you need to add sockets to your skeletal mesh (SK_Mannequin for me). Open the skeletal mesh and, for example, add a socket to middle_01_r and middle_01_l with RightClick => AddSocket.

Those stones are going to be a Blueprint of type Actor. In this Blueprint add a StaticMesh (AddComponent), drag it on DefaultSceneRoot to overwrite it and add a BoxCollision as a child of the StaticMesh. The StaticMesh should be your stone (choose it on the right side, for me it is the 1M_Cube at a Scale of 0,25 in x,y,z) with a CollisionPreset of type OverlapAll. The BoxCollision should be big enough, so choose a Scale of 7-8. For the function/event that is going to be triggered, go to ClassDefaults and set AutoReceiveInput to Player0. In your EventGraph of your Stone Blueprint add this:

The Stone in these pitcures is my renamed StaticMesh. Drag it from your component list and drop it in your EventGraph. For your Keyboard E Event you have to set ConsumeInput to Disabled (select the event and go to input on the right side). To add the OnComponentOverlapEvents click on the BoxCollision in your component list and add the Events from the right side (green buttons at the bottom).
What is happening in the Blueprint: When your character overlaps your Stone(you have to place it in the level) the OnComponentBeginOverlap will be triggered and the IsOverlap will be set to true. When you press E you will get a reference to your Player. After that you have to check can you still pick up stones and are you in the overlapping area. If this is true and this is your first stone, disable collision (causes weird behaviour in your hands), attach it to one of the sockets and increment your CurrentInventory. If you already have 1 stone, the same will happen but for the other socket in your other hand. If your CurrentInventory is equal to your MaxInventory nothing will happen (that’s up to you to add it in).

1 Like