My Projectiles have a public UParticleSystemComponent *TrailParticles, which I reference in the constructor by
TrailParticles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MovementParticles"));
TrailParticles->AttachTo(CapsuleVisual); //the root component, a UStaticMeshComponent
TrailParticles->bAutoActivate = true;
TrailParticles->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleAsset(TEXT("/Game/Materials/Trail.Trail"));
if (ParticleAsset.Succeeded())
{
TrailParticles->SetTemplate(ParticleAsset.Object);
if (Debug)
{
UE_LOG(LogTemp, Log, TEXT("%s: Created TrailParticles."), *GetDebugName(this));
}
}
And in another class, I am spawning these Projectiles by
while (i < 100)
{
Projectile = World->SpawnActor<AProjectile>(FVector(2500.f, 2500.f, -1000.f), FRotator(0.0f), SpawnInfos);
if (Projectile != NULL)
{
Projectile->SetActorHiddenInGame(true);
Projectile->ResetSpeed(); //sets the moving vector to 0, so Tick() won't move them
Projectile->TrailParticles->ToggleActive();
if (ProjectileQueue->Enqueue(Projectile))
i++;
}
}
I am preallocating some Projectiles, so I am then adding these into my TQueue, that’s why I want to disable them at first. The Ribbons should be activated, when I use the projectiles in the game, which works: