InputController bindings not working when delegated to Character

Hello everyone,

This is a little something that I found out while going on a full C++ approach with PlayerControllers. When setting the InputBindings inside the SetupInputComponent(), this kind of setting works:

InputComponent->BindAction("Jump", IE_Pressed, this, &ASomeCharacter::Jump);

In this case, Jump() is merely a gloryfied wrapper of the same method invoked directly on the character.

On the other hand, this one doesn’t:

InputComponent->BindAction("Jump", IE_Pressed, GetCharacter(), &ACharacter::Jump);

// This is the definition of GetRealCharacter in my .h

FORCEINLINE class ASomeCharacter* GetRealCharacter () const { return (ASomeCharacter*) this->GetCharacter(); }

Of course, setting those bindings directly on the character works like a charm, but what if I wanted to keep all this logic in the PlayerController? Jumping or Turning do not appear to me as something so character-specific, but I expected the binding to work nonetheless.

The thing is both BindAction and BindAxis, in this context, expect a SomeCharacterController* as the target and, likely, that’s rendering the binding unsuccessful.

I can go on with those wrappers, but it seems hacky to just wrap the actuall call in a local method. Of course, my approach could be flawed from scratch so I’d like to know if I’m missing something while binding directly to the character or if this scenario (the wrappers) is the approach to take if you just want this kind of control logic in your Controller.

Thanks for the quick response Andrew, and sorry for my slow reply. Indeed, that’s helpful. Whenever I want to control another pawn, this controller should unpossess the previous one and possess the new one, right?. Now, as for the wrappers, is that a valid (or at least expected) approach? Binding Action and Axis to local methods I use to issue commands to the possessed pawn? Thanks again!