Programmatically spawn particles?

I know this is an old topic but I was trying the same thing after following a projectile tutorial from Unreal Engine and it didn’t work

3 - Implementing Projectiles

	if (!ImpactParticles)
	{
		ImpactParticles = CreateDefaultSubobject<UParticleSystem>(TEXT("ImpactParticles"));
		static ConstructorHelpers::FObjectFinder<UParticleSystem>ParticleSystem(TEXT("ParticleSystem'/Game/SciFiWeapDark/FX/Particles/P_Grenade_Explosion_Light.P_Grenade_Explosion_Light'"));
		if (ParticleSystem.Succeeded())
		{
			//ImpactParticles->SetupAttachment(GetRootComponent());
		}

	}
void ADEProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
{
	if (OtherActor != this && OtherComponent->IsSimulatingPhysics())
	{
		OtherComponent->AddImpulseAtLocation(ProjectileMovementComponent->Velocity * 100.0f, Hit.ImpactPoint);

		if (ImpactParticles)
		{
			UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, Hit.ImpactPoint);			
			UE_LOG(LogTemp, Warning, TEXT("ImpactParticles from projectile"));

		}
	}

	Destroy();
}
1 Like