StartSpectatingOnly crashes my game

See title. I recently just added this line and crashed. Thought I missed something (I was working from the challenge slide at the time) and went on with the video… my code matches Ben’s.

Here is my code:
Source
void ATankPlayerController::ProcessPossessedTankDeath()
{
UE_LOG(LogTemp, Warning, TEXT(“Player tank died :(”));
if (!GetPawn()) { return; }
StartSpectatingOnly();
}
Header
UFUNCTION()
void ProcessPossessedTankDeath();

Repo is here.

1 Like

Also in case it’s related, my AI tanks have stopped moving. When I log out, they are attempting to move via MoveToActor() and RequestDirectMove() (you can see my commented out logs in my repo). The strange thing is that the player tank can move just fine, which would imply it’s something with the Tank AI controller. But the Tank AI controller is passing sensible values to the TankMovementComponent.

Try attaching the debugger in VS to see where it crashes.

That gave me the information I needed, thanks! I had somehow missed where we protected the player pawn pointer in TankAIController::tick() and was crashing there.

Now I’ll play around and see if I can figure out the reason why the AI has stopped moving. If you see anything obvious please let me know, and I’ll post again if I can’t figure it out.

I had this problem. The following is what I did, and my idea of why the AI stopped working.

I noticed that within the Tick of the AI Controller, the player’s tank is referenced. This reference becomes null when the spectator mode is initiated. But the ensure is not called, or if it is called, it is done only once and the return happens only once. I added an if(!PlayerTank) before the first use of PlayerTank within the Tank AI controller Tick function, set that to return out of the function. Due to this, the AI is no longer aiming at any tanks. My tanks still move, though I am not figuring out where they are moving to. I hope this helps out someone in the future.

2 Likes

Ryan,

Thanks, saved me. I put the check in the PlayerController and AIController.

Privacy & Terms