Still the particle effects after all these solutions here

Hi there,

I am about to throw my PC out of the window xD. This issue is driving me nuts. So I have screened through this forum and tried every suggestion here. Nothing seemed to have worked for me. However, the trigger “Particle.play” is translated over to the log of Unity meaning that when pressing space it should display that visual.

        if (audioSource.isPlaying == false) //no sound overlay

        {
            audioSource.PlayOneShot(mainEngine);
            mainEngineParticles.Play();

            print("Particle running");

I see in the log file that the condition is triggered to play the particle effect. However, It won’t show it in game. I have tried every single tweak on the inspection slider too (as suggested here in some of the posts). The only way I get this to work is by pressing “Play on awake”. From there I also tried to “disable” that effect in the code when pressing space. Doesnt work either. So here I am trying to figure out this problem for a good 2 hours and about to move the whole rocket thing into the trash can xD. But yeah will need to experiment around. Someone still having issues with the particles even with all these suggestions here?

There is clearly something interrupting the visual display of

engineParticles.Play();

EDIT:

I also cant make the death particles running on impact. I will submit here the whole code, maybe you can spot something.

public class FlyingInput : MonoBehaviour
{
    Rigidbody rigidBody;
    AudioSource audioSource;
    [SerializeField] float rcsThrust = 100F; // Definition of the rotation speed of the rocket
    [SerializeField] float mainThrust = 100F;
    [SerializeField] AudioClip mainEngine;
    [SerializeField] AudioClip GameOver;
    [SerializeField] AudioClip IdleThrust;
    [SerializeField] AudioClip Success;
    [SerializeField] ParticleSystem mainEngineParticles;
    [SerializeField] ParticleSystem successParticles;
    
    [SerializeField] ParticleSystem deathParticles;


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

    public void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
        sceneNumber = SceneManager.GetActiveScene().buildIndex;
        


    }

    int currentScene = SceneManager.GetActiveScene().buildIndex;
    public void OnCollisionEnter(Collision collision)
    {
        if (state != State.Alive) { return; }
        
        switch (collision.gameObject.tag)
        {
          
            
            case "Friendly":
                print("Friend");

                break;

            case "Final":
                state = State.Transcending;
                
                    if (sceneNumber == 1)

                {
                    Invoke("LoadCurrentScene", 1f);
                }

                else if (sceneNumber == 0)
                {
                    Invoke("LoadNextScene", 1f);
                }

                break;

                default:

                state = State.Dying;
                    if (sceneNumber == 0)
                    {
                    deathParticles.Play();
                    audioSource.Stop();
                    audioSource.PlayOneShot(GameOver);
                    
                    
                    

                    Invoke("LoadCurrentScene", 4f);
                    
                }

                    else if (sceneNumber == 1) {
                    deathParticles.Play();
                    audioSource.Stop();
                    audioSource.PlayOneShot(GameOver);
                    
                    { Invoke("LoadNextScene", 4f); }
                }
                    break;
                }
    }

    public void LoadNextScene()
    {
        SceneManager.LoadScene(1);
    }

    public void LoadCurrentScene()
    {
        SceneManager.LoadScene(0);
    }

    public void Update() {

        
        if (state == State.Alive)


        {
           
            ProcessInput();
        }

        void ProcessInput()
        {
            Thrust();

            MovementAxis();


        }

        void MovementAxis()
        {
            if (Input.GetKey(KeyCode.W))

            {
                rigidBody.AddRelativeForce(Vector3.forward);

            }

            if (Input.GetKey(KeyCode.S))

            {
                rigidBody.AddRelativeForce(Vector3.down);
            }


            else Rotate();
        }
    
    }

    public void Rotate()


    
       
        {
        rigidBody.freezeRotation = true;
        float rotationSpeed = rcsThrust * Time.deltaTime;

        if (Input.GetKey(KeyCode.A))

            
        {
            
                transform.Rotate(Vector3.forward * rotationSpeed);

            }

            else if (Input.GetKey(KeyCode.D))

            {
            
            transform.Rotate(Vector3.back * rotationSpeed);

            }
        rigidBody.freezeRotation = false;
    }
    
        
    

    public void Thrust()
    {
        float Booster = mainThrust * Time.deltaTime;
       
       
        if (Input.GetKey(KeyCode.Space))
            ApplyThrust(Booster);

       
        else
        {
            audioSource.Stop();
            mainEngineParticles.Stop();
        }
    }
   
    public void ApplyThrust(float Booster)
        
     
    {
        rigidBody.AddRelativeForce(Vector3.up * Booster);

       
        if (audioSource.isPlaying == false) //no sound overlay

        {
            audioSource.PlayOneShot(mainEngine);
            mainEngineParticles.Play();

            print("Particle running");

            

        }




    }
}

Hi Johnny,

I hope I understood your problem correctly. The particles don’t appear during runtime, do they? If so, make sure that the particle system from your Hierarchy is referenced in your Rocket component.

Hi Nina,

If I understand you correctly you mean if the 3 particle effects are assigned in the hierarchy view? If yes, I believe I did it right:

After I put those effects in the hierarchy of that Ship object I have prefabbed the whole thing. I also checked if the effects are in an bad position but they are sticking to that ship. For example if I let the Engine effect “play awake” and it will be correctly displayed on the object. What really bugs me is that the code is recognised as “particle effect to be shown” but it doesnt want to do it, even if the condition is assigned.

I will look into it tomorrow when I have a fresh mind. Now I just want to delete the whole project and start from scratch xD

Thank you very much

Best

Johnny

Here are also some of my settings:

On the particle effect self:

The ship object:

However, I do have an error message which doesnt prevent me to play it in runtime. It has to do with the assigning index numbers of the scenes if I am right. I dont think it has something to do with it but I post that message too:

However, I do have an error message which doesnt prevent me to play it in runtime.

Maybe we should fix this first to ensure that it’s not the reason why the particles don’t appear. Do you have a script named FlyingInput? If so, share it here, please.

Regarding the particle system, I’d suggest to enable “Prewarm”. This often fixes certain problems.

Last but not least, remove the references to the particle systems in the Rocket component in the Hierarchy and readd the particle systems from your Hierarchy. This way, you make sure that the problem is not caused by a “wrong” reference.

Hi Nina,

With regards to the error message: The script “FlyingInput” is the only script I have for this game rn.
I am calling the index number of the screen as I wanted to add conditions when the game goes to the next level and when he returns to first level or the current level (if dead or accomplishing level 2). The error message is associated with this one code:

public void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
        **sceneNumber = SceneManager.GetActiveScene().buildIndex;**
}

    int currentScene = SceneManager.GetActiveScene().buildIndex;

and then further used here:

public void OnCollisionEnter(Collision collision)
    {
        if (state != State.Alive) { return; }
        
        switch (collision.gameObject.tag)
        {
          
            
            case "Friendly":
                print("Friend");

                break;

            case "Final":
                state = State.Transcending;
                
                    if (sceneNumber == 1)

                {
                    Invoke("LoadCurrentScene", 1f);
                }

                else if (sceneNumber == 0)
                {
                    Invoke("LoadNextScene", 1f);
                }

                break;

                default:

                state = State.Dying;
                    if (sceneNumber == 0)
                    {
                    deathParticles.Play();
                    audioSource.Stop();
                    audioSource.PlayOneShot(GameOver);
                    
                    
                    

                    Invoke("LoadCurrentScene", 4f);
                    
                }

                    else if (sceneNumber == 1) {
                    deathParticles.Play();
                    audioSource.Stop();
                    audioSource.PlayOneShot(GameOver);
                    
                    { Invoke("LoadNextScene", 4f); }
                }
                    break;
                }

I dont think the error message is interfering with the particle issue I got.

Regarding your other suggestions: Yes, I already tested with “Prewarm”. That didnt helped. Also redragged the particle effects into hierarchy didnt helped.

I will try to isolate the thing on a new level and make a new script just for the thrust movement and see if the problem is already deep in the basis of the whole script xD

Thank you for your help

Best

Johnny

Interesting. The Start method is not a constructor. The error message does not make much sense to me. You didn’t call GetActiveScene elsewhere, did you? At least, I cannot find another method call in the FlyingInput class. Maybe you could test the getter which was suggested in this thread.

Or did you change the code you posted in #1? int currentScene = SceneManager.GetActiveScene().buildIndex; is not allowed at instance level. That method should be called only when the scene was loaded. Start gets called after a scene was loaded.

That’s a very good idea, and I would have suggested the same. Add Debug.Logs to your code.

You could also comment out the entire code and readd the code step by step to see when the code stops working as expected. Maybe the Play method gets called each frame or multiple times. Or the particle system gets stopped at some point. In the if and else if blocks the same lines of code get called. Only the scene name is different. Since this is the “Dying” state, the code does not make much sense to me because why would you load the same scene when the scene number is 0, and the next scene is the sceneNumber is 1. Is this what is supposed to happen?

You could also write a Test class for your rocket where you only have the code for the particle system in the Update method. If the particles don’t show up either, the problem is not the code but the particle system. For testing purposes, you could create a simple particle system and reference that one in the FlyingInput component.

Hey there Nina,

I have now reduced the script to the essentials regarding the particle effect issue in a Sandbox environment.

So here is the fun part:

If I tell that he should play the particle effect before the upward vector movement it will play it for a millisec before the stop kicks in and will NOT return to that code. I tried to override that code by setting duration in inspector with the result that the whole initialisation is ignored and the particle effect wont show up.

Then I tested it with the “pause” command. There it works perfectly with the exception that the particles will be graphically only removed when pressing thrust again (the particles are remaining visible and frozen at activation place).

EDIT: If you then activate (prewarm) by using the code as per “Edited Code Section” below, it works. I guess thats a solution but I would like to understand why xD

public class KeyInputSandbox : MonoBehaviour
{
    
    Rigidbody rigidBody;
    [SerializeField] float rcsThrust = 100F; // Definition of the rotation speed of the rocket
    [SerializeField] float mainThrust = 100F;
    [SerializeField] ParticleSystem mainEngineParticles;
    



    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
    }

    

   
    void Update()
    {
     
        
            float Booster = mainThrust * Time.deltaTime;


        if (Input.GetKey(KeyCode.Space))
        {
            mainEngineParticles.Play();
            rigidBody.AddRelativeForce(Vector3.up * Booster);

                }
        else

        {

            mainEngineParticles.Stop(); // when switching with Pause command the loop is working perfectly
        }
        }

     




        }

EDITED Code

 public void Thrust()
    {

        if (Input.GetKey(KeyCode.Space))
        {
            mainEngineParticles.Play();
            print("Particle running");
        }

        else
        { mainEngineParticles.Stop();

        }
        
        float Booster = mainThrust * Time.deltaTime;
       
       
        if (Input.GetKey(KeyCode.Space))
            ApplyThrust(Booster);

       
        else
        {
            audioSource.Stop();
            
        }
    }
   
    public void ApplyThrust(float Booster)
        
     
    {
        rigidBody.AddRelativeForce(Vector3.up * Booster);

       
        if (audioSource.isPlaying == false) //no sound overlay

        {
            audioSource.PlayOneShot(mainEngine);
          

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms