Why is AIController's position of detached ChildActorComponent centered on parent and not the child actor?

I have child actors. I then detach them. The child actor (no longer a child) still has no AIController, so I create one with SpawnDefaultController(). The problem is that the controller is located at the center of the parent actor instead of having the same location as the actor it has possessed. Why is this happening?

What’s even stranger is that I used the debugger and SpawnDefaultController() does set the correct position, but when the function returns, the position changes. I see nothing that would do this. I’m guessing it’s because the build is in release mode (DebugGameEditor).

Is there a way to have the controller take the position of the actor it possesses? The problem is that path finding (AIMoveTo) no longer works because it has the wrong starting position.

Here is my code:

    TArray<UChildActorComponent*> Components;
    this->GetComponents<UChildActorComponent>(Components);
    for (int i = 0; i < Components.Num(); i++)
    {
      ACarrierFlightLeader* ShipLeader = Cast<ACarrierFlightLeader>(Components[i]->GetChildActor());
      if (ShipLeader == nullptr)
        continue;

      ShipLeader->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
      ShipLeader->SpawnDefaultController();
    }

Ok, I found it. Usually, Z coordinates don’t matter much. But in SpawnDefaultController(), it calls GetNavAgentLocation() where it gets the actor’s position and subtracts BaseEyeHeight. I thought it was set to 4, but it’s actually set to 64.

This is for 3d pathfinding, so just need to set BaseEyeHeight to 0. It’s a property on the Pawn.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.