Download

Spawn Emitter At Location crash

I am trying to spawn an Emitter with the default UE4 Explosion but it seems I am doing something wrong…


void AProyectil::NotifyHit(UPrimitiveComponent * MyComp, AActor * Other, UPrimitiveComponent * OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult & Hit)
{
        Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);

        static ConstructorHelpers::FObjectFinder<UParticleSystem> Particle(TEXT("/Game/StarterContent/Particles/P_Explosion.P_Explosion"));
        if (Particle.Succeeded())
        {
               UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), Particle.Object, GetActorLocation());
        }

        Destroy();
}

this code result in an editor crash, please can someone tell me why?

ConstructorHelpers::FObjectFinder can only be called in the constructor. You should try something like the following.

In header



	UParticleSystem* ParticleFX1


In constructor



        static ConstructorHelpers::FObjectFinder<UParticleSystem> Particle(TEXT("/Game/StarterContent/Particles/P_Explosion.P_Explosion"));
        ParticleFX1 = Particle.Object;


In NotifyHit function



	if(ParticleFX1)
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ParticleFX1, GetActorLocation());


That was exactly the problem, Thank you very much !