[help] Particle effects no longer working

[EDIT-SOLVED]

The issue is the Particle Effects CAN NOT be linked via the prefabs. For whatever reason, they don’t register.

Set Particle Effects as children to your Object, THEN drag those over to “Main Engine Particles” etc, and it all works the way it’s supposed to. :persevere:


Hey there,

I’m actually on section 66 Make Game Moments, but I’ve run into a snag with my particle effects.

I had my particle effects working fantastically - got them aligned to where they are supposed to be, triggered properly, the whole bit. Worked as advertised, and was very happy with it.

Then in an absolute brilliant stroke of unprecedented genius, I deleted the audio source from my space ship.

Things … broke. Badly. I do not recommend this course of action, at all. I’m still picking up the pieces, and my neighbors have begun to shun me.

It got so bad, in fact, that I ditched my rocket.cs, and just copy/pasted from the Rocket.cs from here Protecting Against NaN and cleaned up the “+'s” out of the code, and added the audio source back in.

Everything works brilliantly again … except the particle effects, which no longer trigger. I have the associated with the Rocket.cs script (see screenshot), so I’m not sure what the issue is, other than I’m overlooking something very obvious. I’ve double checked both the prefab and the rocket, to no avail.

This is my code here. As far as I can tell, everything should be working, but it’s not. :anguished:

using UnityEngine;
using UnityEngine.SceneManagement;

public class Rocket : MonoBehaviour
{
[SerializeField] float rcsThrust = 100f;
[SerializeField] float mainThrust = 100f;
[SerializeField] float levelLoadDelay = 2f;

[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip success;
[SerializeField] AudioClip death;

[SerializeField] ParticleSystem mainEngineParticles;
[SerializeField] ParticleSystem successParticles;
[SerializeField] ParticleSystem deathParticles;

Rigidbody rigidBody;
AudioSource audioSource;

enum State { Alive, Dying, Transcending }
State state = State.Alive;

// Use this for initialization
void Start()
{
    rigidBody = GetComponent<Rigidbody>();
    audioSource = GetComponent<AudioSource>();
}

// Update is called once per frame
void Update()
{
    if (state == State.Alive)
    {
        RespondToThrustInput();
        RespondToRotateInput();
    }
}

void OnCollisionEnter(Collision collision)
{
    if (state != State.Alive) { return; } // ignore collisions when dead

    switch (collision.gameObject.tag)
    {
        case "Friendly":
            // do nothing
            break;
        case "Finish":
            StartSuccessSequence();
            break;
        default:
            StartDeathSequence();
            break;
    }
}

private void StartSuccessSequence()
{
    state = State.Transcending;
    audioSource.Stop();
    audioSource.PlayOneShot(success);
    successParticles.Play();
    Invoke("LoadNextLevel", levelLoadDelay);
}

private void StartDeathSequence()
{
    state = State.Dying;
    audioSource.Stop();
    audioSource.PlayOneShot(death);
    deathParticles.Play();
    Invoke("LoadFirstLevel", levelLoadDelay);
}

private void LoadNextLevel()
{
    SceneManager.LoadScene(1); // todo allow for more than 2 levels
}

private void LoadFirstLevel()
{
    SceneManager.LoadScene(0);
}

private void RespondToThrustInput()
{
    if (Input.GetKey(KeyCode.Space)) // can thrust while rotating
    {
        ApplyThrust();
    }
    else
    {
        audioSource.Stop();
        mainEngineParticles.Stop();
    }
}

private void ApplyThrust()
{
    rigidBody.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
    if (!audioSource.isPlaying) // so it doesn't layer
    {
        audioSource.PlayOneShot(mainEngine);
    }
    mainEngineParticles.Play();
}

private void RespondToRotateInput()
{
    rigidBody.freezeRotation = true; // take manual control of rotation

    float rotationThisFrame = rcsThrust * Time.deltaTime;
    if (Input.GetKey(KeyCode.A))
    {
        transform.Rotate(Vector3.forward * rotationThisFrame);
    }
    else if (Input.GetKey(KeyCode.D))
    {
        transform.Rotate(-Vector3.forward * rotationThisFrame);
    }

    rigidBody.freezeRotation = false; // resume physics control of rotation
}
}

Just wanted to let you know, that you are my hero! I had the exact same issue and I was about to lose my mind, because I couldn’t figure out the issue. Your solution worked perfect for me, thanks!

2 Likes

same exact thing just happened to me and i spent all day trying to fix this, should of stopped by here 1st and saved a lot of headache

1 Like

I’m having this issue. I broke my prefab and set my engine particles to none. I then put the particles back on my rocket, and from there, dragged it into Main Engine Particles, and it still doesn’t work. I feel like I’m missing something in the solved message. By “set as child” you just mean to put them on the rocket object right?

And my issue might be slightly different, since I very occasionally see the engine particles come out.

1 Like

Hey John - yes. Place the particle systems on the rocket, and then from there (the rocket) drag them over to Rocket (script).

If on the off chance you’re dragging them from the prefab, they won’t work.

Hope that helps!
~S

THANK YOU!

I’m glad I went in here within a half hour from running in to this problem. Wouldn’t have been able to go to sleep if I hadn’t gotten it right. =)

Privacy & Terms