I built my own trigger (just recreated the Pulse trigger is all really), trying to figure out how to access the public variables, pretty sure I’m close but missing something fundamental to c++ that’s just whooshing over my head right now.
Everything compiles fine but it crashes and shoots me this error at play:
Here is the trigger h file:
#include "CoreMinimal.h"
#include "InputTriggers.h"
#include "DifGuns.generated.h"
/**
*
*/
UCLASS()
class PEWPEWKACHEW_API UDifGuns : public UInputTriggerTimedBase
{
GENERATED_BODY()
private:
int32 TriggerCount = 0;
protected:
virtual ETriggerState UpdateState_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue ModifiedValue, float DeltaTime) override;
public:
// Whether to trigger when the input first exceeds the actuation threshold or wait for the first interval?
UPROPERTY(EditAnywhere, Config, BlueprintReadWrite, Category = "Trigger Settings")
bool bTriggerOnStart = true;
// How long between each trigger fire while input is held, in seconds?
UPROPERTY(EditAnywhere, Config, BlueprintReadWrite, Category = "Trigger Settings", meta = (ClampMin = "0"))
float Interval = 1.0f;
// How many times can the trigger fire while input is held? (0 = no limit)
UPROPERTY(EditAnywhere, Config, BlueprintReadWrite, Category = "Trigger Settings", meta = (ClampMin = "0"))
int32 TriggerLimit = 0;
virtual FString GetDebugState() const override { return HeldDuration ? FString::Printf(TEXT("Triggers:%d/%d, Interval:%.2f/%.2f"), TriggerCount, TriggerLimit, (HeldDuration / (Interval * (TriggerCount + 1))), Interval) : FString(); }
};
Here is the trigger cpp file:
#include "DifGuns.h"
ETriggerState UDifGuns::UpdateState_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue ModifiedValue, float DeltaTime)
{
ETriggerState State = Super::UpdateState_Implementation(PlayerInput, ModifiedValue, DeltaTime);
if (State == ETriggerState::Ongoing)
{
// If the repeat count limit has not been reached
if (TriggerLimit == 0 || TriggerCount < TriggerLimit)
{
// Trigger when HeldDuration exceeds the interval threshold, optionally trigger on initial actuation
if (HeldDuration > (Interval * (bTriggerOnStart ? TriggerCount : TriggerCount + 1)))
{
++TriggerCount;
State = ETriggerState::Triggered;
}
}
else
{
State = ETriggerState::None;
}
}
else
{
// Reset repeat count
TriggerCount = 0;
}
return State;
}
Here is what I’m basically trying to do in the main player cpp file:
switch (gunType) {
case 0:
difGunTrigger->TriggerLimit = 8;
difGunTrigger->Interval = 0.5f;
break;
case 1:
difGunTrigger->TriggerLimit = 20;
difGunTrigger->Interval = 0.2f;
break;
}