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();
}