My Actor doesn't react to input

I have create an actor that handle input and play animation but I don’t seem to be able to make it work. I know there is something missing but I can’t seem to find it.

MyActorAnimation.h

#include "GameFramework/Actor.h"
#include "MyActorAnimation.generated.h"

UCLASS()
class MYCARPROJECT_API AMyActorAnimation : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyActorAnimation();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	void PlayJump();

	UInputComponent* InputComponent;

	UPROPERTY(EditAnywhere) USkeletalMeshComponent* Mesh;
	UPROPERTY(EditAnywhere) TArray<UAnimationAsset*> Anim;
	
};

MyActorAnimation.cpp

#include "MyCarProject.h"
#include "MyActorAnimation.h"


// Sets default values
AMyActorAnimation::AMyActorAnimation()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	
}

// Called when the game starts or when spawned
void AMyActorAnimation::BeginPlay()
{
	Super::BeginPlay();
	InputComponent = ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, "Input Component");


	InputComponent->BindAction("Jump", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlayJump);

}


// Called every frame
void AMyActorAnimation::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void AMyActorAnimation::PlayJump() {
	GEngine->AddOnScreenDebugMessage(-1, -1, FColor::Red, TEXT("Input1"));
	Mesh->PlayAnimation(Anim[0], true);
}

Have you tried adding “Jump” to the list of handled input events in the Project Settings?

I would be quite surprised if unreal magically knows about the InputComponent you’ve created. Check out this thread.

You can also have a look at using EnableInput

Yes I had it, i just forgot to specified it

I have already try with no success

Hey -

static voidlol was correct in that you need to enable input for the actor. If you override the EnableInput function that static voidlol linked, you can bind your input as you did in line 20 of the .cpp. You can then call the Enable Input function on begin play to have that actor set to receive input when the game beings.

Cheers

I finally found my answer I simply needed to get the input component from the PlayerController.
The EnableInput was also nessecary

void AMyActorAnimation::BeginPlay()
{
	Super::BeginPlay();

	APlayerController* PC = GetWorld()->GetFirstPlayerController();

	EnableInput(PC);

	PC->InputComponent->BindAction("Jump", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlayJump);
	PC->InputComponent->BindAction("Walk", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlayWalk);
	PC->InputComponent->BindAction("Run", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlayRun);
	PC->InputComponent->BindAction("Slash", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlaySlash);
	PC->InputComponent->BindAction("Shoot", EInputEvent::IE_Pressed, this, &AMyActorAnimation::PlayShoot);

}

Was missing something else, but I found it I post my anwser