Gettting Possessed Actor From PlayerInput

I can’t find the function on PlayerInput to get the currently possessed actor for the life of me. PlayerInput is on its own Pawn in scene and possesses the player actor as defined in the “default Modes”.

Does the PlayerInput.cs class have a reference to the actor it possessed or do I need to find it manually in scene.

Thanks for any help.

Inputs or Pawns don’t possess other Pawns – controllers possess Pawns.
Also, PlayerInput.cs is not a file in the Unreal source code.

In PlayerInput.cpp, the only reference to an actor is some code that is not included in the shipping build:

			APlayerController*	Actor = Cast<APlayerController>(GetOuter());
			UPlayer* Player = Actor ? Actor->Player : NULL;

My guess is that, whatever you’re trying to do, you should do in a PlayerController subclass, not a PlayerInput.

Sorry I wrote that poorly. I’ve been looking at code from two different projects for too long.

In any case what I meant to say:
I have a pawn:

  1. MachineCharacter
    And An Actor:
  2. MachinePlayerController

On MachinePlayerController I have a “APlayerController” component. The "“APlayerController” component possess the “MachineCharacter” actor.
I’m trying to find the MachineCharacter actor FROM the APlayerController.

That said I got it working. It turns out it was getting compiled out, I still don’t know why its getting compiled out but the original problem is solved.

//called on input when the player pushes the right stick.

void AMachinePlayerController::SetAimVector(FVector AimVector, const APawn *MyPawn)

//I'm passing in mypawn but finding it again for sanity as this hasn't been working.
	APawn* Pawn = GetPawn();  
	//I want the actor being controlled.
	AActor* MyActor = Cast<AActor>(Pawn);
	if (!MyActor) return;  //If I remove this line the actor is NOT NULL and the code runs just fine.  If I leave it in everything is getting compiled out. 0_0
	USkeletalMeshComponent *Mesh = MyActor->FindComponentByClass<USkeletalMeshComponent>();

	if (!Mesh) return;
	UPlayerAnim *AnimInstance = Cast<UPlayerAnim>( Mesh->GetAnimInstance() );
	if (!AnimInstance) return;

	AnimInstance->AimVector = AimVector;

It looks like the APlayerController sets its “Pawn” variable to the pawn it is possessing in code. So calling GetPawn returns the possessed pawn. I was also assuming GetPawn would return the pawn the APlayerController is on and didn’t realize its on an Actor not a Pawn. I’d kill for some C++ documentation. :wink:


I just learned the power of
#pragma optimize("", off)

Everything is now wonderful. Amazing.

Okay, that makes much more sense :slight_smile:

If you get different behavior when optimizing versus not, either your code, or the compiler, is terribly broken, and you need to spend some time toggling that on and off and observing the behaviors, to figure out which it is.
If you just ignore that and sweep it under the rug, there will be some part of your development process that you don’t understand, and that will lurk like an iceberg under the water and kill you sometime later.