BlueprintNativeEvent is causing Access violation

Hello everyone,

I’m trying to use a BlueprintNativeEvent in my code and one specific part of my code is causing a Access Violation:

======= .h ========

UFUNCTION(BlueprintNativeEvent, meta = (DisplayName = "Apply Effect"))
void ApplyEffect(AGenericCharacter* Receiver);

======= .cpp ======

void USkillEffect::ApplyEffect_Implementation(AGenericCharacter* Receiver)
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("ApplyEffect"));

======= call ======

USkillEffect* SkillEffect = Cast<USkillEffect>(SkillEffects[i]);

Everything goes fine until the code be executed:

Access violation - code c0000005 (first/second chance not available)


I’m using a similar implementation in other part of the project without any problem… Is there something wrong in my implementation?

I found the solution with this topic

The problem was that the USkillEffect was not a valid instance… I changed the row:

USkillEffect* SkillEffect = Cast<USkillEffect>(SkillEffects[i]);


USkillEffect* SkillEffect = NewObject<USkillEffect>(this->GetOuter(), SkillEffects[i]);

and it worked…

Thanks everyone