Handling Pawn Death - Casting the tower Question

Hello All,

When I was going through this lecture I thought to myself why are we casting that way to the Tower, when the way were casting to the Tank made so much more sense - that and I couldn’t really follow the code. So after playtesting and NOT having the tower destroyed, I decided to do just that and changed the code, and I found out that we can’t do it that way because the final parameter in the GetPlayerPawn() requires us to put in a value for PlayerIndex - and we don’t have one as it us never set as it isn’t a possessed character - damn. Question: Is there a a better way of doing this or is this really the only way?

As for my problem, I had the if braces mixed up, no wonder the HandleDestruction function wasn’t being called.

There’s almost always multiple ways to solve a given problem, this isn’t one of the rare cases.

  1. Make HandleDestruction virtual. Virtual functions are covered in the next section so maybe bookmark this problem and try solve it that way once you understand them?
  2. Do everything in the base pawn’s handle destruction.
    There’s IsPlayerControlled that you can use to determine whether the pawn should be destroyed or just hidden.
    APawn::IsPlayerControlled | Unreal Engine Documentation
1 Like

Thanks for the reply. I am looking forward to learning about these virtual functions. The only things that comes close is the virtual BeginPlay() function, but, never really had them explained.

When it comes to coding in Unreal I put more faith in your guesses than most people facts :grin:.

1 Like

Yeah, they aren’t beginner friendly so only using them is done as it’s necessary to work with the engine.
Actually covering them and making your own is done in the last section otherwise it would most likely alienate a lot of people.

:scream:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms