For two map placed actors, if one actor B's non root component is attached to another actor A, the attachment is not retained when actor A reruns its construction script, such as when moving actor A in the editor.

AActor::RerunConstructionScripts() attempts to cache and restore attached components. However, the logic assumes that any attached actors are attached via their root component, which is not necessarily true. While the following code there does find attached actors who are attached via their non-root component:

// If there are attached objects detach them and store the socket names
TArray<AActor*> AttachedActors;

the function then proceeds to assume that the attached actor's root component is how that actor is attached to this one:

USceneComponent* EachRoot = AttachedActor->GetRootComponent();
// If the component we are attached to is about to go away...
if (EachRoot && EachRoot->GetAttachParent() && EachRoot->GetAttachParent()->IsCreatedByConstructionScript()) 

The attached actor's non-root component is not processed, so their attachment to this actor won't be reattached.

I suggest considering either to:

  • Update AActor::RerunConstructionScripts() logic to also reattach non-root components
  • Or add warning messages/ensures to AActor::RerunConstructionScripts() or USceneComponent::K2_AttachToComponent() that we don't support non-root attachments for map actors... i.e. surface the limitation to the user rather than silently breaking hierarchy.
Steps to Reproduce

See attached repro UE 5.3 project.

Repro steps:

  • Create an actor blueprint BP_Parent and give it a Cube root component.
  • Create an actor blueprint BP_SelfAttachingChild and
    • Give it a Scene root component.
    • Give it a Cone child component
    • Give it a publicly visible BP_Parent pointer variable
    • On ConstructionScript, if the BP_Parent pointer is set, attach the Cone (the non-root) to BP_Parent's root component with Attach Component to Component
    • On BeginPlay, print the name of Cone's AttachParent
  • Place a BP_Parent and BP_SelfAttachingChild in the map
  • Set the BP_SelfAttachingChild's BP_Parent pointer to the placed BP_Parent
  • Start PIE and observe that the printed name of Cone's Parent is the BP_Parent's root component (correct). Exit PIE.
  • Move the BP_Parent and start PIE again.
  • Observe: Cone's parent is now null
  • Expected: Cone's parent is still BP_Parent's root

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-204110 in the post.

Login to Vote

ComponentUE - Gameplay - Components
Affects Versions5.
Target Fix5.5
CreatedJan 17, 2024
UpdatedFeb 16, 2024
View Jira Issue