Download

Picking up Items with my hand?

So I have this setup right now

eda03bffa0.png

The interfaces of interest are: I_Pickup, I_Interact and I_Inventory.

I got I_Interact to work. Basically it just gives items the “Use” command so that when you look at a door for example, you can press E to open or close the door. If you look a Soda Can Dispenser and press E though it will dispense a Soda Can. Makes sense. The I_Inventory interface is supposed to be used when you want to have items that can be added to your inventory.

The one I am currently having trouble with is I_Pickup. This interface is supposed to make you able to pick up the item and hold it in your hand but I don’t know how to do this. Currently I got something like this:

ef5285c46a2abb3735758b9692676952d1ec7f48.png

But nothing happens when I Left or Right Click (I have it hooked up to both). I made sure that Left Hand Empty and Right Hand Empty are set to True as well so that I can pick it up and I made sure that the item I try to pick up (in this case a soda can) actually implements I_Pickup. But no dice. In my mannequin I have these sockets:

b48f624133a03374d14b9c1b827efe9124440f13.jpeg

I think its because you attach it to the Player Controller and the Controller has no socket with those names.
Also i would use “Snap to target, keep World scale.” and depending on the collision, u might geht some problems aswell.

That code looks solid.

A few more details would help us debug. Where does the execution line stop when you left/right click? Could be that the trace doesnt return a hit cause collision is disabled. Could be isInMenu is defaulted to true. Could be soda can isnt set to “movable”. What specific behaivor happens? Any errors in the message log?

Have you tried going to file > refresh nodes? Sometimes its a bug in the editor.

  • The Code Executes to Completion
  • The Collision is there because I have a trace line that checks whether I am looking at something that implements one of the interfaces and when I look at the soda can it shows this:
    a7d897c797.jpg
  • isInMenu defaults to false
  • The Soda Can has physics enabled
  • No Errors in the log

^^ I think this is the answer :slight_smile:

Okay so I tried to change it to this:

25e3fa519b.png

Still nothing happens :confused:

Are u 100% sure Mesh2P is the right mesh? If so u should check if u get the correct mesh from LineTraceCheck. Or Check if you even get this far with some print nodes.

Well the Mesh2P is model itself. Wouldn’t I use that model to get the bones?
Or do I need to somehow get the skeleton??

I had another idea which was to pretty much despawn the object, and spawn an object as a component on my character. But I think that could get a big messy to keep track of when I have to then let go of the item without having to do excessive casting checks…

No you just need the mesh with the bones and the right bone names.
But you have Mesh and Mesh2P so i thought maybe its the other one.
Could you show me whats behind LineTraceCheck?

Yeah sure. A bit of background though. This is based on the first person template originally and then I took the rig and model from the 3rd Person Template and put a Camera on a socket so it looks like real first person view. The Mesh component is inherited from, I guess, Character Blueprint and I can’t remove it. So I just left it there.

c2585073c42ffaac78e2e13651c98cae4329bb72.png

So that might be your problem.
175x is not far enough and you return a self reference and attaching urself to urself is not possible (i guess).
Dont set urself as return value, rather let it give something empty back and test it if its valid.

The reason for the distance is because I fire the Line Trace every frame so when I get within range of an item I can interact with, text shows up on my screen to indicate so.
I’ve tested several lengths and 175 seems to be the perfect length.

Now I return Self if it’s false, so that my “Implements Interface” check fails.
If I don’t do this then it will keep holding on to the last reference it got which means if I, say, used a door by pressing E then wherever I face, unless I face an interactive thing, I can press E again to interact with that door. No matter how far away it is and no matter if I look at it or not.

Hm…
I dont know what else could be wrong here.
Print out the names of the object(s) and see for sure if you get the right ones.
Thats all i can think of right now :frowning:

Okay I removed the Mesh2P and used the inherited Mesh instead. Now I actually grab the item to my hand but it’s really shaking all over and making me move weird some times.

Turn of the collision for ur Soda. (after or befor AttachActorToComponent)
Your Character is colliding with the Soda now and its not working out when you attach something.

Yeah I did that now, but for some reason whenever I attach the thing, it falls to the floor while being attached to me.
By turning collision off, it now falls through the world while being attached.

A dirty solution could be to manually set its transform before attaching to make sure its where its supposed to be.

Like…every frame?

Not what I said but that will DEFINITELY work. Thats similar to how the engine does it under the hood anyways right? And its only two objects tops. What youre afraid a modern CPU cant handle the math?

You can try setting the transform and then do an attach keeping world location. See if its a problem with attachment itself or just snappig to the specified joints

So it falls?
Why do objects fall?
Disable physics/gravity (not sure if you need to disable both but gravity for sure).
But dont forget to enable collision / gravitiy / physics when you unattach it.