Hi,
I created a gizmo that works in the runtime in C++. Right now, I have a problem, the gizmo is inherited from the AActor class. I need a left mouse pressed button to work in the actor. So my question is how to bind the function in the actor? The online tutorial is all about the binding in the character or pawn but there is no such tutorial in actor.
Right now, I try to use the InputComponent in the AActor and cast it to the EnhancedInputComponent then bind the function with it, but it will not trigger the function. In a third-person template for testing and here is the code:
In EnhancedInputActor.h
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
class UInputAction* TestAction;
void Test(FInputActionValue& Value);
In EnhancedInputActor.cpp
void AEnhancedInputActor::BeginPlay()
{
Super::BeginPlay();
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
if (PlayerController)
{
EnableInput(PlayerController);
}
if (InputComponent)
{
UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent);
EnhancedInputComponent->BindAction(TestAction, ETriggerEvent::Triggered, this, &AEnhancedInputActor::Test);
}
}
void AEnhancedInputActor::Test(FInputActionValue& Value)
{
UE_LOG(LogTemp, Warning, TEXT("In Test"));
}
In this code, if I write this way, the “BindAction” will report an error that there is no match function with these parameters. And I have to change this
EnhancedInputComponent->BindAction(TestAction, ETriggerEvent::Triggered, this, FName("Test"));
The action mapping uses the default mapping coming with the template and is added in the third-person C++ file. I create a new Input action in the blueprint and assign that action to the TestAction variable in the actor blueprint and add this action in the default mapping with a button T.
But this is not working when I press the button.
Thanks for your reply.