'UGameplayStatics Emitter Attached but not completing

I have created a particle effect and I am attaching it using UGameplayStatics::SpawnEmitterAttached(Elecricity, gunMesh, TEXT("MuzzleFlashSocket")); but the particle effect isn't completing.

Electricity = UParticleSystem, gunMesh = USkeletalMeshComponent, TEXT("MuzzleFlashSocket") = Name of the socket.

I have tried setting both KillOnComplete and KillOnDeactivate but to no avail.

Thanks for any help



Solution 1:[1]

Check OutputLog : LogScript: Warning: UGameplayStatics::SpawnEmitterAttached: NULL AttachComponent specified!

theMesh = Cast<UStaticMeshComponent>(GetDefaultSubobjectByName(TEXT("Gun_SkeletalMesh")));

OR

theMesh = Cast<UStaticMeshComponent>(this->FindComponentByClass(UStaticMeshComponent::StaticClass()));

Otherwise

theMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Gun_SkeletalMesh"));
theMesh->SetupAttachment(RootComponent);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1