XaiJu
Megan Fox
Megan Fox

patreon


The right way to attach a mesh to a socket in Unreal

This is another of those things that was super frustrating to google, with a ton of bad answers, and it's possibly because of a UI bug! I'm leaving this public as a result, so maybe a good answer will be findable. So let's dig in:

If you search around on this topic, you'll mostly find people settling on the "right" way being AttachComponentToComponent, and that's. Fine. That isn't wrong. But. It's limited. You'll generally need to snap-to-target if you attach this way, which means there will be no offset possible between the socket and where you want the thing to end up.

So you might try to work around this. You'll attach-relative, thinking "oh but this is in construction script! this is on begin play! surely that's safe right now, because the animation won't have started yet" and hahahahahaha. This is a race condition. Actually, you'll find that the animation state is INCONSISTENT at that point, and your attached objects will end up at arbitrary positions! Fun!

Then you'll go "oh, well, I guess I have to snap-to-target and then have a second offset vector that I apply after attachment" and NO STOP. This is where the Right way comes in. Open your class BP, click the mesh component, go over to Details, and click this. Click the button. That's it. No, you can't type into the field, yes it looks disabled, but really. Click the button.

Extra Bonus of doing it this way? Now click the mesh component and check out the Viewport for your BP there. See how you can drag the thing around? Rotate it? Yay! You don't need that whole second vector or rotator, and you can just position it exactly where you want. Note that you can pause animation in the upper left of the Viewport, which you'll probably need to do here.

But This Doesn't Work

Now here's where the bug comes in. You may find that when you click that button, nothing happens!

Well. Guess what? If you're using collapsing windows? So you've collapsed Components, meaning Components window is collapsed when you click over here? Oops! This button won't work. Hopefully someday this will be fixed, and a future searcher will find this section and go "dunno it works for me".

So anyways, make SURE that if you're using collapsing windows, that you've pinned Components and Details open before trying this. Then it'll work.


More Creators