Hi my friends! I’m doing some learning project - which is 100% C++ game, and I’m stack with Input Action. I see I can use ValueType in Constructor, but how do I implement a trigger? Shouldn’t it work like this?
Hey, maybe something like this would work for you?
#include "InputAction.h"
#include "InputTrigger.h"
#include "InputModifiers.h"
UInputAction* MoveAction = NewObject<UInputAction>();
MoveAction->ValueType = EInputActionValueType::Axis2D;
// Create the input action
UInputAction* MoveAction = NewObject<UInputAction>();
MoveAction->ValueType = EInputActionValueType::Axis2D;
// Create a Hold Trigger
UInputTriggerHold* HoldTrigger = NewObject<UInputTriggerHold>();
HoldTrigger->HoldTimeThreshold = 0.5f; // Hold time in seconds
// Add the trigger to the action
MoveAction->Triggers.Add(HoldTrigger);
PlayerInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ASomeFunction::Move);
void ASomeFunction::Move(const FInputActionValue& Value)
{
FVector2D MovementVector = Value.Get<FVector2D>();
AddMovementInput(FVector(MovementVector.X, MovementVector.Y, 0.0f));
}
Instead of using Triggers.Add(...) directly (since Triggers is a TArray of UInputTrigger pointers), you need to create instances of specific trigger classes like UInputTriggerDown, UInputTriggerHold, etc.
Recently I saw a talk from Ari (an Epic developer evangelist) and he said “there’s no prize for making a project purely in blueprint”. Well that’s equally true for trying to make a project 100% in C++. Some things are designed to be created as content in the Editor. Things like maps, UIs and input actions. You’re not supposed to construct these objects in C++, you’re supposed to make them in the content browser and reference them through asset references and the mapping contexts.
I understand that it’s a project to learn, but there’s no point learning it way that it is never actually intended to be used based on an entirely arbitrary requirement that makes no sense. It also makes it harder for the community to help you because all of the advice and direction is going to be based on how you’re supposed to have things setup.
I’m not trying to be discouraging, just trying to redirect your energies.