What do I use in my EnhancedInputComponent->BindAction instead of 'this' when setting up from Controller instead of Character?

Move and Look work, Jump and StopJumping do not. Code compiles without errors.
Copy/Pasted from TP_ThirdPersonCharacter, but this is being setup in a controller instead of a character.

	// Jumping, does not work
	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this->GetCharacter(), &ACharacter::Jump);
	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this->GetCharacter(), &ACharacter::StopJumping);

	// Moving, works
	EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &APlayerCharacterController::Move);
	// Looking, works
	EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &APlayerCharacterController::Look);

I’m guessing GetCharacter() returns null at the time of binding the actions

If you want to do it this way, maybe you should bind functions on the player controller that call functions on the controlled pawn instead?

That’s essentially what I ended up doing with GetCharacter(), but I was hoping to try to do it by calling the Character class directly without the extra functions. Got similar advice on Discord so this is probably the right way to go.

This is what I ended up with. Thanks for the right direction!

// PlayerCharacterController.h
void Jump();
void StopJumping();


// PlayerCharacterController.cpp
void APlayerCharacterController::Jump()
{
	GetCharacter()->Jump();
}
void APlayerCharacterController::StopJumping()
{
	GetCharacter()->StopJumping();
}


EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &APlayerCharacterController::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &APlayerCharacterController::StopJumping);

this will crash if GetCharacter() returns nullptr though

Perhaps you can bind and unbind the actions as you were doing before, but do it in OnPossessedPawnChanged or in OnPossess/OnUnPossess

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