User mode data execution error exception

Hi, I’m coming here because I have a problem I can’t solve.
So, I have a base class “Events” and some classes inheriting from it.

UCLASS()
class IKOLIA_API UEventsAIDirector : public UObject
{
	GENERATED_BODY()

public:
	virtual void Trigger(const FTransform& Transform);
	virtual void SetNbEnemies(int Nb);
};

//INHERITING CLASS :
UCLASS()
class IKOLIA_API UEvent_RandomEnemies : public UEventsAIDirector
{
	GENERATED_BODY()

public:
	virtual void Trigger(const FTransform& Transform) override;
	virtual void SetNbEnemies(int Nb) override;
private:
	int TotalEnemiesToSpawn = 7;
};

And in another class, I want to be able to store those events in a TArray and select one to Trigger it, I then make a TArray of the parent class to store its children like so :

void UAI_Director::Register_Events(TArray<UEventsAIDirector*>& EventsList)
{
	UEventsAIDirector* RandomEnemies = NewObject<UEventsAIDirector>(this,UEvent_RandomEnemies::StaticClass(), "Random Enemies Event");
	
	EventsList.Add(RandomEnemies);
}

But I am randomly triggering an exception when trying to do this :

                EventsList[0]->SetNbEnemies(10);
		EventsList[0]->Trigger(Transform2);

The problem is, this happens randomly, its not a consistant error and I don’t have a clue on how to solve it :

Any ideas? Thanks !

1 Like

I encountered this error with a private save game variable in c++. I think the randomness comes from the value being garbage collected.

I found a post on stack overflow with the same error and temporarily disabled my antivirus as it suggested and after I did I started getting a normal access violation error.

Then, I discovered from the following post that I needed to mark my variable as a UPROPERTY() to prevent it from being garbage collected

1 Like