Actor detaches from component when duplicated

I have a component that can attach its self to other components based on the proximity to another static mesh. It does this after the actor (that it’s a part of) is moved. This seems to work fine. If you duplicate the attached actor, it will become detached if it and the actor/component it’s attached to are not in the persistent level.

Using the project I provided, you can reproduce this by…

  1. Open TestMap.uproject
  2. Make sure that TestMap_B is the active map.
  3. Grab the blue cube (BP_AutoAttachActor) and move it close to the cube underneath it (BP_SpinningActor).
  4. Once you see it’s attached, PIE. The blue cube appears attached to the spinning cube.
  5. Stop the PIE instance and duplicate the blue cube. Alt-Drag and Ctrl+D seem to produce the same results.
  6. Place the new cube onto one of the spinning cubes.
  7. Start a PIE instance.
  8. The original cube is detached, but the new cube is attached.
    [Attachment Removed]

Steps to Reproduce
Hello!

I’m running into an issue where an actor is becoming detached when it’s duplicated and in a sub-level.

To start off, I have a component that can attach its self to other components based on the proximity to another static mesh. It does this after the actor (that it’s a part of) is moved. This seems to work fine. If you duplicate the attached actor, it will become detached if it and the actor/component it’s attached to are not in the persistent level.

[Attachment Removed]

Just pinging this thread to make sure someone sees it.

[Attachment Removed]

Hi,

I had a look at the project and I think the problem is that BP_AutoAttachActor is part of the TestMap while it’s being attached to BP_SpinningActor that is part of TestMap_B. This is resulting in a bug where the BP_SpinningActor instance from the Editor world is being dragged in PIE.

[Image Removed]

If I duplicate BP_AutoAttachActor, the new instances is part of TestMap_B and properly attaches to the right instance, ie the PIE one.

[Image Removed]

I’ll have a colleague validate the information but I’m pretty sure that Actors can be attached to instances that are not in the same level.

Regards,

Martin

[Attachment Removed]

Sorry, I meant to move that into TestMap_B. If you move it to TestMap_B, save the maps, move it so that it attaches, and hit play. It’ll look attached correctly. If you re-open the map, it’ll be snapped to the center of that box it was attached to.

[Attachment Removed]

I’ve uploaded a video illustrating the issue and how to reproduce it.

[Attachment Removed]

Hi,

I ran some extra tests and I’m not sure that you can preserve that type of attachment through a save\load cycle. You might get more success if you attach to a socket in the Parent StaticMesh but I doubt you want to add sockets to everything. I traced the problem back to the calculation of the transform at load time. It appears that some of the hierarchy is not properly initialized but I couldn’t find a way to force an update.

You might have to store the desired transform in the UAutoAttachComponent and restore it after the initialization.

I should not that attaching to the GetDefaultAttachComponent (the rootcomponent of the Hit Actor) does properly restore the transform. I suspect that the Parent Actor has not been properly initialized at the attachment time and its child ComponentToWorld is not valid at that point.

I reached out to a few colleagues that are more familiar with that part of the engine. I’ll report back if they have some suggestions.

Regards,

Martin

[Attachment Removed]