Exception Access Violation Crash Issue

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;

		}

You trigger runs fine. Did an implementation in a test scene.

Your error is stemming from from MainPlayer.cpp line 74

Yeah, that’s what the last block of code I shared is from.

is gunType an int or enum?

An int. Although I think the problem is pointing to the trigger. I’m not sure how. Just tried this:

difGunTrigger = NewObject<UDifGuns>();

But doesn’t work. I’m assuming because it just is making a new version of the trigger instead of modifying the existing trigger file’s public variables.

The error says it starts here:

difGunTrigger->TriggerLimit = 8;

I have the difGunTrigger defined in my header file like this:

UPROPERTY(EditAnywhere, BlueprintReadOnly)
		UDifGuns* difGunTrigger;

Works on my end.

Here is the character file and difguns.
Look over them and check where you have differences.

Perhaps you are not implementing the newObject in the right place?

files.zip (4.4 KB)

OFC api and character name is different but that can be ignored. The code is what counts.

Here is a full third person proj implementation

1 key = to trigger
2 key = to call change (switches parameters on dif)

I think the difference is that you’re creating and adding the trigger in code, which I didn’t even think about but it makes a lot of sense. I mega borked my game so need some time to unbork it before trying it out. But it makes a lot of sense to go that way than trying to change a trigger set in Unreal instead.

I spent a lot of time trying to grab a trigger from that array to manipulate than thinking to just add my own trigger to said array. >.>

You said you for sure got it working with the limits?

It’s not overriding any of the public properties for me.

In the project i sent you I added on screen messages showing the current increment / limit

I’m not seeing how you swap the case in the project you sent me.

As an aside, also noticing an issue where the trigger gets added permanently to the array each time the game is run.

void AtppCharacter::Change(int32 gunType) {

	switch (gunType) {
	case 0:
		difGunTrigger->TriggerLimit = 8;
		difGunTrigger->Interval = 0.5f;
		break;
	case 1:
		difGunTrigger->TriggerLimit = 20;
		difGunTrigger->Interval = 0.2f;
		break;

	}
}

I just call it from bp (the character), I didn’t need to go into making a specific input action and mapping for a test.

I honestly don’t know how to make gunType = 1 in what you sent. I’m not seeing it in any of the BPs or anything.

I swapped it and it still goes to 8 instead of 20. It’s adopting the setting called here:

difGunTrigger = NewObject<UDifGuns>();
		difGunTrigger->TriggerLimit = 8;
		GunAction->Triggers.Add(difGunTrigger);

But it’s not switching the values on Change()

Change is being called but the class seems almost immutable internally.
Perhaps you need to force an update on the class in some way like updateResources on other classes?.

I’ve even tried removing and adding the triggers again after the changes. Still holds the 8 value

I had an idea. If it needed a new trigger then fine, I could erase the array and create a new one on swap, nbd.

Unfortunately, this doesn’t work for some reason. I can set the trigger with one set of variables, I can swap it, but the effect doesn’t take place in the same play session despite unreal saying it has only the new trigger attached.

At this point I think I’ve ultimately wasted hours on something impossible. = /

Just gonna have to use clunky timer ■■■■ like everyone else I suppose.

I appreciate your attempts at helping me with this.