[Fixed] Lecture_118_Cannot Find the Player's Tank (version 4.14 btw)

I cannot seem to get my AI controllers to find the player tank, but not because the search comes back as a nullptr. Instead, they all seem to think the first AI tank they find has the FirstPlayerController.

I have the BattleTankGameMode, PlayerController, Tank_BP, and the rest configured correctly as far as I can tell, and I’m using the GetWorld()->GetFirstPlayerController()->GetPawn() just like Ben is. Any ideas?

Oh, and on a side note: while using GetPawn()->GetName() on the player’s tank returns a reasonable name, doing so on the Ai tanks brings back a really long name like ‘s 910350720s’; is that normal?

Doesn’t sound like it. Do you have your project hosted anywhere like GitHub so I can take a look at it?

Not currently; I may put it up soon if I need to; I did find out recently that if I change the AI to be possessed by the PlayerController Blueprint that the GetName returns what it’s supposed to, but it won’t if it is possessed by the AIController (plus I tried converting this to a blueprint and the oddity still exists). Plus when I had both the Player’s tank and AI possessed by the same BP and I tried doing a search for the FirstPlayerController()->GetPawn()->GetName() it still returns a long series of numbers like I mentioned before.

Added: Found the problem. I cannot say I understand entirely what happened or why it happened, but in a couple lines of code I had ‘s%’ instead of ‘%s’, and when I fixed it it began working properly.

Privacy & Terms