Hello!
I am relatively in-experienced in C++ in general, but have done a few courses. I am attempting to spawn a niagara system similar to the way one would spawn a normal particle system with UGameplayStatics. I have found a few reddit threads with example code, but i still get a crash for an unhandled exception because I believe I am not properly setting up my system class pointer used in the UNiagaraFunctionLibrary::SpawnSystemAtLocation() function.
I have Niagara added to my build module list. I am using this in my header :
UPROPERTY(EditAnywhere, Category = "Effects")
UNiagaraSystem* OpenEffect;
I am forward declaring the UNiagaraSystem class in my header. Then I have these includes in my cpp:
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraSystem.h"
Then I use this in my implementation:
if (OpenEffect->IsValid())
{
UNiagaraComponent* NewEffect = UNiagaraFunctionLibrary::SpawnSystemAtLocation(
this,
OpenEffect,
GetOwner()->GetActorLocation(),
FRotator(1),
FVector(1),
true,
true,
ENCPoolMethod::AutoRelease,
true);
}
I get a crash whenever that code is run in runtime that gives me the unhandled exception at a mem address and references the line with the if statement, so I am assuming that my OpenEffect pointer is somehow not resolving properly. I’m sure I am doing somethign very basically wrong, but without any examples for using Niagara in C++ in any of the documentation I am at a loss. I can succesfully add a Niagara component to my Actor class and use the component’s Activate() function to get what I need for now, but am very curious how I can go about spawning without the built in Actor component as done with the UGameplayStatics method for triggering old cascade particles.
Any pointers would be much appreciated! Thanks
P