Shmoopy1701:
The UParticleSystem is loaded from content. The ParticleSystemComponent (assuming you are attaching to an actor) is what is spawned at run time. Example:
In the .h file:
// particle system definition
UPROPERTY(EditInstanceOnly)
UParticleSystem* _effectFx = nullptr;
// particle system component spawned at runtime
UPROPERTY(EditInstanceOnly)
UParticleSystemComponent* _effectFxComponent = nullptr;
In the .cpp file:
// load particle system
FString particleEffectPath = "/Game/ParticleEffects/Fire/ElectricFires/ElectricFire";
_effectFx = Cast<UParticleSystem>(StaticLoadObject(UParticleSystem::StaticClass(), NULL, *particleEffectPath));
// play effect
_effectFxComponent = UGameplayStatics::SpawnEmitterAttached(_effectFx,
RootComponent,
NAME_None,
FVector::ZeroVector,
FRotator::ZeroRotator,
EAttachLocation::SnapToTarget,
false);
Thanks for the example, in the C++ area less people seem to write.
I don’t know this way, but thanks for that.
I’ll write down my previous way and maybe you can add what I am missing? Would be super nice. I think I am only missing one small step. But I don’t know it.
It’s really hard to teach yourself everything if you don’t fully understand the context.
In .h
UPROPERTY(EditAnywhere)
UParticleSystem* MeinPartikel = nullptr;
UPROPERTY(EditAnywhere)
UParticleSystemComponent* KugelPartikel = nullptr;
In.cpp
KugelPartikel = CreateDefaultSubobject<UParticleSystemComponent>(TEXT(“MeinPartikel”));
UGameplayStatics::SpawnEmitterAttached(MeinPartikel, MeineScene);
//There is still missing the step, that somehow from the component, which has the particle in it, it is filled into the UParticleSystem variable.