Why my particlesystemcomponent not working?

Greetings!

I’ve been trying to create an Actor that activates a particlesystem if an event happens. The Actor has 2 events, one of them deactivates the particle system the other activates it. First I made a reference to an AEmitter that was placed in the editor and that time it worked fine, but I dont want a reference to another Actor so I tried to make it with particlesystemcomponent and it does not work.

My Code:

/** Header */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Portal")
UParticleSystem* ParticleTemplate;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Portal")
UParticleSystemComponent* Particle;

/** CPP */
/** Event activating the particle component */
	if (!Particle)
	{
		Particle = UGameplayStatics::SpawnEmitterAttached(ParticleTemplate, RootComponent, NAME_None, GetActorLocation(), GetActorRotation(), EAttachLocation::KeepWorldPosition, false);
	}

	Particle->ActivateSystem(true);

/** Event deactivating the particle component */
if (Particle)
{
	Particle->DeactivateSystem();
}

I hope someone has some suggestions or ideas why this is not working because I’ve been trying to make this happen for a lot of time and I am out of ideas.

Thank you for your time.

Sincerely,

Remove the ! in front of the particle system. You are checking if the particle system is not equal to null, when you should be checking if it is equal to null instead.

You have a logical flow doen slightly incorrect, here i changed it for ya :slight_smile: The problem was that you created the particle first, and then ALWAYS deactivated it, since if(Particle) is always true after you create it.

 /** Header */
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Portal")
 UParticleSystem* ParticleTemplate;
 
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Portal")
 UParticleSystemComponent* Particle;
 
 /** CPP */
 /** Event activating the particle component */
     // if no particle, create and activate
     if (!Particle)
     {
         Particle = UGameplayStatics::SpawnEmitterAttached(ParticleTemplate, RootComponent, NAME_None, GetActorLocation(), GetActorRotation(), EAttachLocation::KeepWorldPosition, false);

         Particle->ActivateSystem(true);
     } else { // exists, deactivate
         Particle->DeactivateSystem();
    }