Using child actor component in c++ gives a few problems

Reproduce in 19.2

In 19.2, you can reproduce the first issue by meeting these conditions (1) calling CreateChildActor() in the constructor. In such a case, the following happens:

  1. CreateChildActor(), of course, calls "CreateChildActor()" (in ChildActorComponent.cpp)
  2. At line 561 of ChildActorComponent.cpp, if the child actor's class has been successfully spawned, the code will call the following:(
  3.  ChildActor->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
    
  4. In Actor.cpp at line 1508, this in turn calls: RootComponent->AttachToComponent(Parent, AttachmentRules, SocketName).
  5. Now since the RootComponent is a sceneComponent and this method is not virtual, then "USceneComponent::AttachToComponent" will be called.
  6. The problem:

    Now since the above ChildActorComponent code unconditionally called AttachToComponent with the attachment rule: “SnapToTargetNotIncludingScale”, the second ensureMsgf in the screenshot will fail since it is “ensuring” that the attachment rules are keepRelative. . (SceneComponent.cpp at line 1678). Specifically, this fails:

    ensureMsgf(AttachmentRules.LocationRule == EAttachmentRule::KeepRelative && AttachmentRules.RotationRule == EAttachmentRule::KeepRelative && AttachmentRules.ScaleRule == EAttachmentRule::KeepRelative, TEXT("AttachToComponent when called from a constructor is only setting up attachment and will always be treated as KeepRelative. Consider calling SetupAttachment directly instead."));
    

Let me know if I missed anything or need further caveats to reproduce.