Search code examples
unreal-engine4unreal-blueprint

UE4 Test if pawn is controlled pawn


I made up a C++ ThirdPersonExample project. I added several ThirdPersonCharacter BP. (TPC BP) I added a variable to the TPC BP.

I play as one of the TPC BP's. The other ones are controlled by AI.

In Event Graph of TPC BP, on Event BeginPlay, I want to set a variable if this current instantiated TPC BP is the controlled pawn - ie it's me playing!

I see that you can set variables.

sample of setting variable

However:

  1. I only want to set a variable if I'm not the Controlled Pawn
  2. I want to also set another variable if I am the Controlled Pawn.

I may be thinking of this the wrong way...any help appreciated.


Solution

  • I think that the easiest solution would be:

    1. Add Event Possessed to TCP BP. This should be fired when your pawn (character) is possessed by a controller.

    2. Since previously mentioned event has parameter - reference to a possessing controller, you can then try to cast that reference to PlayerController and AIController ( or their descendants).

    3. Final step is to implement specific code for both types of possessing controllers (when cast was successful).