- Home /
Particle System is not Playing
I made a simple spaceship that has a particlesystem. When I press "space" button, spaceship should fly and particle system should instantiate and play. But it's not playing. It seems in hierarchy as clone but not playing.
Those are codes :
void FlyShip()
{
if (Input.GetKey(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpForce);
if (!takeoffSound.isPlaying)
{
// _rocketJetParticle is gameobject.
_rocketJetParticle = Instantiate(rocketJetParticle, new Vector3(transform.position.x, transform.position.y - 4, transform.position.z), transform.rotation);
takeoffSound.Play();
}
}
else
{
//Destroy(_rocketJetParticle);
takeoffSound.Stop();
}
}
In the particle system settings, is it set to Play On Awake?
Answer by Megaboy238 · Feb 21, 2021 at 09:53 PM
Your not really doing it the best way and my way is not the best either but easier.
Create Particle System
Make sure to uncheck 'Play On Awake'
Add Particle system to rocket as child
Position Particle system on the rocket at the boosters
Add [SerializeField] private ParticleSystem _rocketJetParticle; to variable list.
Change void FlyShip() as per below.
Add Particle systems to script in inspector.
FlyShip() { if (Input.GetKey(KeyCode.Space)) { rb.AddForce(Vector3.up * jumpForce);
if (!takeoffSound.isPlaying)
{
// Start Particle System.
_rocketJetParticle.Play();
takeoffSound.Play();
}
}
else
{
_rocketJetParticle.Stop();
takeoffSound.Stop();
}
}
Actually, ı did what you said before. But I think for more optimization, instantiating and destroying is better than that.
Answer by rh_galaxy · Feb 21, 2021 at 10:03 PM
You shouldn't Instantiate (and destroy) the particle system all the time, just let it exist all the time as a child object and do play and stop.
I don't know when you run FlyShip(), but if it's in update this will result in creating a new particle system every frame, which is not what you want.
public ParticleSystem oThruster; //set in inspector by dragging the particle system to the variable
ParticleSystem.EmissionModule oThrusterEmission;
oThrusterEmission = oThruster.emission;
//then set on
oThrusterEmission.enabled = true;
//or off
oThrusterEmission.enabled = false;
Hi, actually I did what you said before. But I think for more optimization, instantiating and destroying is better than that. What do you think ?
Your answer
![](https://koobas.hobune.stream/wayback/20220613025550im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to instantiate particle effect after destroying it 2 Answers
Is it better to use ParticleSystems on one GameObject OR instantiate ParticleSystems? 1 Answer
Best way to spread particle system? 1 Answer
Lightning Effect (Particle System?) 1 Answer
Can particle simulation be disabled in the Scene Editor? 0 Answers