Set parent bone inside the constructor

Hi, so this code when called in the constructor sets the parent for my gun to be the “Hands” skeletal mesh, but it does not set it as a child to the bone named “hand_l”.

Gun->SetupAttachment(Hands, TEXT("hand_l"));

When i call

	Gun->AttachToComponent(Hands, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("hand_l"));

inside the BeginPlay event, it detects the bone and it attaches to it. When i call this line of code inside the constructor, the game just crashes.

My problem is that i cannot edit the default location and the rotation of the gun inside the blueprint editor if i set the parent bone in the BeginPlay, and making it look right is tricky using “SetRelativeTransform” (the gun should look like it is in the player’s hand). Any ideea what am i doing wrong or why the bone socket is not being detected inside the constructor?

After all, i discovered that this is a bug. For anyone running into this bug in the future, here is the fix:

  1. Close the engine.
  2. Change the variable name to something else.
  3. Change the name of the component (the name you put in CreateDefaultSubobject)

Compile the code inside Visual Studio and start the engine again. Everything should work fine this time.
Make sure the engine is closed when you try this fix.