rcapote
(rcapote)
1
I’m trying to spawn particles in C++, but it’s not working. No crashes or errors, just simply the particles don’t spawn.
In the header:
TSubclassOf<class UParticleSystem> Particle;
UParticleSystem* ParticleSystem;
In the constructor:
static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleSystemClass(TEXT("/Game/StarterContent/Particles/P_Smoke"));
Particle = (UClass*)ParticleSystemClass.Object->GetClass();
ParticleSystem = Cast<UParticleSystem>(StaticConstructObject(Particle));
And when I try to spawn the particles:
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ParticleSystem, GetActorLocation(), FRotator::ZeroRotator, true);
EDIT: Looks like what I had to do was set the particle effect in the editor, instead of trying to get and instance it in code.
1 Like
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