How To Detect a Mesh Using Line Trace, THEN set another mesh to that detected mesh?

Hi all,

Overview: I want to pick up an object, have my player see that I’m holding the object, and then place the object down where it is supposed to go.

Detecting Volume: I have a volume in a level, and anything in the volume becomes an object that can be picked up. This way, I can design this little puzzle on the fly - just drag meshes in and out of the volume. Currently, I have a blueprint that contains a volume, checks for meshes that collide with it on “begin play” and assigns any mesh that’s inside of the volume with a tag “pickable”. This works.

Line Trace: My player character blueprint has a line trace, and checks to see when I’m looking at an object, and determines if it has a tag called “pickable”. This works.

Spawning the pickable object: This is where I lose all confidence. I’ve tried both spawning an actor based on a “pickable” Blueprint in the volume described above. However, I’ve also tried SETTING a mesh component based on the “pickable” mesh in the volume described above.

Below, I outline what I’m doing based on a static mesh in the volume.

The following takes place in the Player Character Blueprint:

I have a static mesh called “Item” in my player character blueprint, in front of the camera in a way that it looks like I’m carrying something if I set that mesh to a specific mesh. It’s empty to begin with - so nothing’s there.

When I hit the E button, I want to set the Player Character Blueprint’s “ITEM” static mesh to the static mesh that is registering with my line trace. For the life of me, nothing I’m doing will work, and I believe it’s because there’s fundamentally something I don’t understand about static meshes.

It seems that if my line trace hits a static mesh, neither the “hit actor” or “hit component” will feed into the “Set Static Mesh” node’s input. I understand why - I know that a static mesh isn’t an actor, and it’s not even a component - I just don’t know how to get the “static mesh” content from a line trace.

I hope this makes sense. I’m attempting to attach an image of my code from the Player Character Blueprint, but I don’t know how everyone makes those hi-res blueprint images (google has not helped an only brings me to 10 year old posts where people suggest this as a thing that UE should be able to export).

Thanks for any help!

The Set Static Mesh node takes in a Static Mesh Object reference, which is not the same as the Static Mesh Component Object, which is the container class for the Static Mesh Object

What you would want to do is take the Hit Component, cast to Static Mesh Component, then from that Get Static Mesh, then you can input that into the Set Static Mesh of your item Static Mesh component.

I hope that helps

Thank you!!!

Yes, I had tried casting to the static mesh component but was SKIPPING the “Get Static Mesh” node. I was trying to promote the “As Static Mesh Component” to a variable and it wasn’t doing what I needed. Thanks so much! This is exactly what my brain was trying to do.