How to attach a particle system to a spawned actor through code?

First of all, the function goes as follows:

static UParticleSystemComponent * SpawnEmitterAttached
(
    class UParticleSystem * EmitterTemplate,
    class USceneComponent * AttachToComponent,
    FName AttachPointName,
    FVector Location,
    FRotator Rotation,
    FVector Scale,
    EAttachLocation::Type LocationType,
    bool bAutoDestroy,
    EPSCPoolMethod PoolingMethod
)

If you’re using this function, use it as follows:

    if (TestActor && YourTemplate && (YourScale.Size() != 0))
    {
     UGameplayStatics::SpawnEmitterAttached(YourTemplate, TestActor->GetRootComponent(), NAME_None, YourLocation, YourRotation, YourScale, EAttachLocation::SnapToTarget, false, EPSCPoolMethod::AutoRelease
    }

That should work :slight_smile: