Raycast trace for sockets

How would I go about creating a raycast which hits sockets connected to an actors’ skeletal mesh? Either blueprints or C++ is fine.

When you hit a skeletal mesh you will hit bones (not entirely sure) not sockets. But you can attach a collision component (box, sphere, capsule) to a socket and hit against that instead.

Hey Daveoh,

You can use a Line Trace by Channel node in Blueprints and then break Out Hit to find Hit Bone or Hit Component. You can’t specify sockets with this node, but as Moss mentions below, you can add a component in character BP in location of socket for same effect. nodes in question look like this:

Hope that helps!

Hey ,

Thanks for your response. Is there a difference between using bones or using sockets to attach objects to an actor? I see in this documentation you use sockets to achieve what I would like to achieve: https://docs.unrealengine.com/latest/INT/Engine/Content/Types/SkeletalMeshes/Sockets/index.html - Is it possible to attach an Actor to a bone in same way you can attach an Actor to a socket?

In end, would you recommend adding bones instead, or adding collision components to sockets?

Bones are used in animation and adding more than you require for animation will impact performance, sockets in turn are cheap, they are just a named position (even adding desired offsets if required).

There are still a few ways where bones are way to go, for example a bone to attach camera to which you can then animate in your animation tool or IK (Inverse Kinetic) handling such as hands that should grab a weapons grip or an edge when implementing climbing.

In short bones are expensive and taken into account by animation system while sockets are just dummy positions. To attach an actor to a bone I would add a socket to that bone and attach actor to sockets, this way you have more flexibility to move socket freely (also I would name bone depending on what you want to attach in our camera example it would be something like camera_pos).

Cheers,
Moss

Thanks for info. How would I attach a collision component to a socket?

next screenshots will show you how I added a new socket to a bone (https://docs.unrealengine.com/latest/INT/Engine/Content/Types/SkeletalMeshes/Sockets/index.html), where mesh that I will attach come from and how to perform attachment.

Thanks for screenshots, but I don’t think that’s what I was looking for. I’d like a collision component attached to a socket, so that I would be able to create a trace which can hit component and then attach something to that socket. Additionally, a component on top of a bone may not be sufficient and sockets can be placed away from bone. Thanks again.

I just added a mesh. but you can add whatever you want. Let me show you how to set it up :smiley: Just give me 5 min :smiley:

following shots are just same, but we add a collision box, now you can add overlap and hit events to it or you can see if a trace hits new box. But take into account to set right collision channel so that trace does not hit characters capsule.

Hey Daveoh,

You probably don’t want to add bones to your character for things that aren’t permanently attached. In this case, if sockets are what you’re looking for, then you can add an empty component to your character, and then attach component to socket location through construction script. Then, when you do your line trace, use Hit Component output and check to see if it’s desired component.

For example, if I have a Socket already set named RightHand, I can create a new Sphere Component in my Character Blueprint. Make sure that collision is set to be detected by LineTrace you’re performing:

16777-linetracecomponentcollision.png

Then, in its Construction Script, I set something like this to attach component to socket:

16779-linetraceforcomponentconstructionscript.png

With that set, you can use Line Trace to detect it:

Let me know if you have any other questions.

EDIT: I posted this before I saw any of Moss’ input, but it looks like we’re both telling you same way to do it. Nice work, Moss!

Yes hahaha With so many screenshots this is like a complete blog post :smiley:

I’m also going to go ahead and enter a Feature Request in our database for Hit Socket Name in our Break Hit Results node. Seems useful.

That would be awesome! It wold be nice if we could specify shape of socket, I think about basic shapes like box, capsule, spehere or even a mesh. Using it to setup a melee weapon system would be super easy with it.

A socket doesn’t have a shape, as it’s basically just a location attached to a bone. I’m not sure I understand benefit of having a shape associated with a socket. Can you give me an example with which that might help?

To simplify setup we discussed here for example. Of course adding a component would work same way but adding an optional shape to socket could make things easier. For example adding a sphere you left and right hand socket for a simple punch implementation.

Because adding the ‘socket hit name’ pin seams a bit strange taking into account that socket is just a point (a bones does refer to a specific place of mesh).

Ah, you’re right, I didn’t think that all way through. I’ll include that in request.

Thank you and Moss! You have both been lots of help and I can see how to do it now! If someone else doesn’t make a wiki page for this then I may do so :slight_smile:

Nice if you create a wiki page for it :smiley: You can use images without issues :smiley: