Component won't attach to SkeletalMesh socket

Hello, I’ve got a skeletal mesh called Mesh and a weapon called WeaponMesh
I’m trying to attach the WeaponMesh to a socket called ‘Weapon’ inside the skeletalmesh.
(Note this has to be done in code, you can’t attach inherited objects inside the editor)

Here is my code in the constructor:

WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
WeaponMesh->SetupAttachment(Mesh, FName("Weapon"));

You can see the WeaponMesh gets added to the mesh just fine, but if you look at the properties… it’s not added to the socket:

To test, I added a SkeletalMesh (shown above) within the editor. That one attaches to the socket just fine:

Why won’t this get added through code? I’m done it many other times and it’s always worked, but this particular one just won’t attach for some reason. Is it because it’s a Skeletalmesh being attached to a socket? Is this a bug?

Maybe some things to check:

  • That the socket can actually be found through code (e.g. use Mesh->DoesSocketExist(FName(“Weapon”))
  • That the attachment code has already executed when you look at the blueprint? Not quite sure here, but if it’s not in the constructor then that code wouldn’t have run yet.
  • Maybe it’s just a display bug in the editor?

Thanks for the suggestions staticvoidlol.

I solved it by removing the Weapon code completely, compiling, and then adding it back in.
Looks like unreal wasn’t updating the fact that I attached it to a mesh, so completely removing it and placing it back with the attachment in place did the job.

This is pretty weird but we are almost in 2019 and the problem still there.

tyvm btw.

Thank you, worked for me on 4.23

It worked for me too on 4.24.3

What eventually worked for me was one or more of the following:

  • Unset and reset character mesh in BP
  • Change attached mesh variable and display name
  • Comment out SetupAttachment code, compile, start engine, quit, uncomment

Annoying bug