Download

UParticleSystemComponent to UParticleSystem

hi, I am still new in C++.

I create a particle component in an actor, select a particle in BP.

The question is: how do I get from UParticleSystemComponent* to UParticleSystem* so I can use SpawnEmitterAttached().

You don’t, the types are unrelated. A ParticleSystemComponent contains a ParticleSystem and plays/stops it etc.

The ParticleSystem is the actual asset in the CB that you want to play.

Thanks for the feedback, but SpawnEmitterAttached() with UParticleSystemComponent* variable does not work.
Or please show me how exactly it would work.

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.

Lol, I have it. Thanks all.