TankAIController fails to cast the tank pawn it owns into a tank pawn


^ I have done everything perfectly, then checked the lecture, he did it identical to I have. The fact that my player tank pawn fetches the pawn that it is possessing, and the fact that the same exact tank pawn shows a message that it does not have a tank pawn, shows that I have done it correctly.


^ and here you can see that the tank pawn blueprint the AI controller is using, is in fact a Tank Pawn class.

So why does an AI controller fail to fetch its possessed pawn when a Player Controller has no problem doing so?

And this screenshot shows that even when I check for any kind of pawn, instead of a tank pawn, the check still fails.

When I simply log the pawn name as so:

UE_LOG(LogTemp, Warning, TEXT("AI Pawn Name: %s"), *(GetPawn()->GetName()))

Then UE4 crashes, meaning the tank AI controller, which exists in the world, does not possess the pawn that it has possessed paradoxically, otherwise, for some reason, the check is failing, or for some reason, UE4 thinks that it owns a differnt pawn, or due to an update or a bug, when an AI controller takes over, it looks for a different specified pawn, which seemingly, you cannot set anywhere…

ok so now it gets wierder. After I compiled the next video’s version, where i told the TankAIController to print out the player tank in the level, the ones that are placed in the level SUDDENLY recognize their own pawn name, however, ones that are spawned into the level using level blueprint, do not know what thier name/pawn is.

It gets wierder.
When the PLAYER tank spawns in the level, it prints dialogue from the TankAIController class! But it isn’t supposed to own an AI controller, since it is possessed by a player controller! How can it have both!? When I eject and check the level objects, there is indeed an AI controller in the level, but there is only one tank!!

And no, there is not any tanks in the level before playing the game/hitting play.

I bet even Ben would be stumped by this if he still used the forums… I’ve looked through every setting possible on my tank blueprint

I wonder though… If these said AI controllers do not have a pawn… Then there must be a way to tell them to possess a pawn? The only problem is I dont know how to look through the world for pawns yet.

Could you provide a link to your repo or a means to view your project?

Yeah u can view it here: https://github.com/TutorialProjects/TankProject/tree/master/Tank_Project

In your Tank BP you have auto possess AI set to “Placed in world or spawned” meaning you would have an AIController spawned for the PlayerTank, but since the PlayerConroller controls that tank that AIController is left with nothing. Change that to “Placed in World”.

Also you aren’t tracking your BattleGrounds map in your repo, had to create one to test your project.

The battlegrounds map is 35 MB for some reason (all because of a simple landscape/heightmap??); I tried to make it stop tracking changes, since the map changes are irrelevant, but how do I do this without deleting it all together? That was actually really bothersome; I thought it was including the old version of the map in the commits.

What you said about whether the tank spawns an AI controller or not makes some sense now, because in the video I do believe Ben had it set to placed in world; meaning the player tank he spawns doesn’t create an AI controller.

Despite this, there is still a couple problems.

For one, It still doesn’t make sense that in my original post it didn’t work then out of nowhere it worked without changing any code except for the AI reporting the Player tank in the world; since i had both a spawned tank and two tanks placed in world. In fact, I just tested what I said in my post, by removing the check for the player tank in the world, and guess what? The tank ai controllers placed in the world can no longer find an attached pawn, despite the removed log having nothing to do with this check. In fact, literally the log was the only thing i commented out, NOT the check. Ontop of this, the tanks that are spawned no longer spawn AI controllers with them , but when reporting what tanks are in the level (the semi-fixed version of my post), well then there is still this problem:

After putting my code back to normal, When I set the tank blueprint AI auto posses to spawned or ‘placed in world or spawned’, the non-player tanks that are spawned create an AI controller, but the controller doesnt possess the tanks, desptite being set to auto possess. It only works for ones placed in world. I know that the logs in the version I gave you dont report the right thing for this example, but if you tried logging it you would see that the spawned AI tanks fail to fetch a possessed pawn (despite being told to auto possess spawned tanks).

If you want you can see the verison where I report this data. I’ll include the map too… but its gonna make the download 35 MB fyi.
Uploading now…
Uploaded: https://github.com/TutorialProjects/TankProject

The map should be fine to keep checked, and it shouldn’t really be changed much so 32MB isn’t a whole lot.

Also not quite sure what you mean, which code?

When i originally posted the Ai tanks were not reporting their pawn names. Then in my first reply to my original post, I noted that when I told the AI Tanks to also report the player tank, suddenly they started also reporting their own pawn names.

Now what i’m saying is not only can I recreate is problem by commenting out a log macro, but the tanks that are told to auto possess on spawn do not do so, only the ones that are placed in level seem to have this effect.

Then I uploaded the same exact version of the project from before but where I told the tanks to log out this information (before they were logging out the distance in meters to where the crosshair was pointing, because thats what I was had last commited since you replied)

Perhaps to make it clearer this is the current UE_LOG requests in the current repository version:

void ATankAIController::BeginPlay() {
	Super::BeginPlay();
	if (Super::GetPawn()) {
		UE_LOG(LogTemp, Warning, TEXT("AI Pawn Name: %s"), *(Super::GetPawn()->GetName()))
	}
	else {
		UE_LOG(LogTemp, Warning, TEXT("AI Pawn Not Found."))
	}

	ATankPawn* PlayerTank = GetPlayerTank();
	if (PlayerTank) {
		UE_LOG(LogTemp, Warning, TEXT("TankAi controller detected player tank: %s"), *(PlayerTank->GetName()))
	}
	else {
		UE_LOG(LogTemp, Warning, TEXT("TankAi Controller couldn't find a player tank in the level."))
	}

}

and when I comment out this part , like so:

	ATankPawn* PlayerTank = GetPlayerTank();
	if (PlayerTank) {
		//UE_LOG(LogTemp, Warning, TEXT("TankAi controller detected player tank: %s"), *(PlayerTank->GetName()))
	}
	else {
		//UE_LOG(LogTemp, Warning, TEXT("TankAi Controller couldn't find a player tank in the level."))
	}

}

Then guess what happens? The program fails to find pawn at Super::GetPawn()->GetName(), when the only thing changed was a UE_LOG !

Maybe its hard to understand because of the bizzare nature of the problem I am describing. But you heard me right…

And as I said, There is also the second problem of the tanks failing to get pawn at Super::GetPawn()->GetName(), when they are spawned in the world, even when setting the tank blueprint to have the AIController auto posses when spawned. They only find GetPawn() when they are told to auto-possess for placed in world. (This is in the version with the extra UE_LOG of the Player Tank Pawn included)

Also i realize the ‘Super::’ syntax is not needed, this was included as a debug attempt.

What’s the purpose of this in your level blueprint

That is to spawn a Tank actor, so the AI can possess it. The posess function doesn’t do anything. I meant to break that event line before pushing the repo. I didnt know off hand how to spawn it using code and that was easier.

Coincidingly, I also didnt know how to force posses the tank using the lost controller. Thats why i was playing around with the blueprint code, but I couldnt figure out how to get the spawned AI Controller, since spawn Actor returns the tank blueprint but not its controller, since the controller does not possess it, and I do not know how to scan the world for controllers, or thus return a list of actors in the world.


Not sure why it’s not possesing it though


Spawn Default Controller

“Spawn default controller for this Pawn, and get possessed by it.”

-Target is Pawn


Hmm interesting i am assuming the default controller is obtained from the pawn class then, in this case, the tank. I tried this but I do not see any additional controller in the world, nonetheless a controller that has possessed the pawn, considering the controller that we are trying to use for this pawn does not return its possessed pawn name, indicating that it does not have one in possession.

Definitely getting 2 AI Controllers

Oh just saw your edit, yeah just like i said as above.

Oh i c, I thought the additional one was a player controller. So yeah the problem persists though…

check this out:

The tank IS indeed possesed, but the bug of its controller fetching the pawn it possesses results in error/nullptr.

Doesn’t the actor need to be possesed by a controller in order to “have” a controller?

Also this works the same if you promote the spawned actor into a new variable.

Perhaps this is a 4.15 source code bug for AI controllers? Where when an AI controller attempts to use the AController’s GetPawn() function it crashes. I dont think AIController overrides the GetPawn() behavior does it?

To verify you or someone would have to attempt this behavior from scratch. Or myself, but I need to proceed on with the damn lectures! lol… ; plus, it could be a problem on my machine. I got a couple other unique bugs so far.

Privacy & Terms