Download

Extending AIController: Some Actors teleport randomly.

Hello.

I’ve been extending my own AIController and setting it to my AI Bot (a chicken) like so:



AMyNPCChicken::AMyNPCChicken(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
	, bGoingForFood(false)
	, tele(false)
{
	AIControllerClass = AMyAIControllerChicken::StaticClass();
}


The reason I want to extend it is because I want to know when the AIBot has reached its destination. I then make a callback to the AI to tell it that the destination is reached,
The Parent actor is actually the base Actor * pointer to the Chicken Actor that I passed previously to my AI Contoller Class the Chicken’s BeginPlay()

If there is another way to find the AI character this controller controls from inside that class, I’d like to hear about it.



void AMyAIControllerChicken::Init(AActor *parent)
{
	Parent = parent;
}

void AMyAIControllerChicken::OnMoveCompleted(FAIRequestID RequestID, EPathFollowingResult::Type Result)
{
	Super::OnMoveCompleted(RequestID, Result);

	if (Parent)
	{
		AMyNPCChicken *chicken = Cast<AMyNPCChicken>(Parent);

		if (chicken)
			chicken->StopWalking();
	}
}


THE PROBLEM:

Note: I don’t spawn my chickens dynamically, I place them directly in my level.

While most of my bots happily do their business, some of them, randomly, in no particular form or order, teleport. And they are not teleporting after a MoveToActor() or MoveToLocation(), in 99% of the cases they teleport after they have reached their destination, even moments later, while the Bot runs idle before issuing another MoveToLocation() call. In some cases, the teleport happens twice during idle time. So I see no connection between a teleport and the fact that a MoveToLocation() has been issued or that the bot has arrived to destination to trigger some weird behavior.

This mostly happen when I spawn many bots. This is not scientific, but I haven’t experienced these weirds teleports when I spawn one or two - but a chicken coop with one or two chickens isn’t very interesting. :slight_smile:

Any hint will be very appreciated.
I’m also looking into the Engine code to trace all my calls. If anyone knows of specific values to check during this process from inside the base AIController class and such, feel free to comment on this.

teleport.png