Download

Child components are at world location instead of root

Version: 4.23

I’ve run into another interesting cunnundrum. So I’ve created a couple capsules for collision and at first they were at their parent’s coordinate. They were at first, then I attempted to scale one via blueprint since I set BlueprintReadWrite. I figured it would be simpler to see as I scaled it. After which it snapped to world 0 in the game despite still showing it being attached to the parent. Also, it doesn’t seem to matter if I use SetupAttachment or not. They come in parented either way and at the wrong location. I did attempt to set their locations manually but that didn’t do anything either. Maybe it’s a glitch?


As you can see, in the world, they’re not with the parent.

Initial setup:

Later Modified (Seems redundant):

Now at one point after setting the attachment to the RocketMesh, a second RocketMesh appeared in the child Blueprint. It crashed shortly after that. I wasn’t able to replicate the issue. But it was after that where the capsules started setting to world 0 instead if the parent. That project file wouldn’t open afterwords and I had to pull down a backup build. But that didn’t fix the world 0 issue.

I also tried explicitly setting the relative and world locations of the components to no avail.

Thoughts?

IIRC Location and rotation aren’t visible in the details panel if there’s something going on between the editor and code; if you can see location and rotation on RocketMesh but not on your capsules then I’m positive that’s it. I ran into a similar situation when parenting arrow components to a scene component. Have you created a new rocket blueprint, or temporarily reparenting the blueprint to refresh it?

You can also try setting your RocketMesh as the RootComponent.

Is it not?

Visually, at least, it would appear that the RocketMesh is the RootComponent in the child Blueprint. But I assumed SetupAttachment would handle that. Either way, I did try RootComponent = RocketMesh; a a just in case. It didn’t change the situation. But now you have me curios. Is it not the root already?

Root components don’t show their translations and rotations so I wouldn’t expect the RocketMesh to show those. But the capsules are not the root.

I did as you suggested and created a new child BP of the C++ class as seen below. It looks to be behaving properly. It’s the one with the balloon. I suppose I could just make a new child BP. It’s weird that it isn’t updating properly. It makes me reluctant to trust the system.

So it appears you both were correct in part. As Lexeon said, the child BP wasn’t updating properly and creating a new child BP from the C++ class was part of the trick. SolidGasGames was also correct in needing to set the RocketMesh as root. Apparently SetupAttachment does not do this for you even though it appeared to be the root in the Blueprint.

Just to test things out, repeated the above a few times to make sure of what was happening. For some reason, child BPs do not update their RootComponents even with a rebuild. Old child BPs still behave as though they are not rooted properly. This seems puzzling as other code changes populate fine.

I find this block of code in AActor::FixupNativeActorComponents() interesting, might have something to do with it since :



// if the user forgot to set one of their native components as the root, 
// we arbitrarily pick one for them (otherwise the SCS could attempt to 
// create its own root, and nest native components under it)
for (USceneComponent* Component : SceneComponents)
     {
          if ((Component == nullptr) ||
          (Component->GetAttachParent() != nullptr) ||
          (Component->CreationMethod != EComponentCreationMethod::Native))
          {
               continue;
          }

         SceneRootComponent = Component;
         Actor->SetRootComponent(Component);
         break;
     }
}


I think (Component->GetAttachParent() != nullptr) is causing this since you never explicitly set your root component with SetRootComponent(). SetupAttachment() simply attaches to a valid component. I believe your rocket is trying to attach to a root component that hasn’t been set while at the same time your actor is going through all your components for a root but can’t find one because it’s never been set for those components. That’s just off the top of my head, though.

Hey Guys! Did you figure this out in the end? Im currently having sort of the same problem where my child scene components relative locations spawns with the root components world space coordinates.


Scene = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
Scene = RootComponent;


TurretRotation = CreateDefaultSubobject<USceneComponent>(TEXT("TurretRotation"));
TurretRotation->SetupAttachment(Scene);

Im using the regular setup for rootcomponent.

Any help is appriciated!

I ■■■■. Just figured it out. i set scene to rootcomponent but it should be rootcomponent = scene; I had reversed it. The child blueprints created from this c++ class do not update though so i guess those have to be created again or tweaked individually.