Building up scenes with all particles simulating

When creating my scenes I would like to be able to see my particles moving, basically simulating as if I was clicking on it in the hierarchy.

Like in this video:

During the creation, his props are moving through shaders ok but what about the Particle System like the sun shafts?

There is no straightforward way to preview all particle systems automatically in the same scene during edit mode because you risk lagging the editor severely when more particle systems are present. The only way to preview a group of particle systems without manually selecting multiple objects is to nest all particle system objects to a same parent object and this parent needs a particle system component as well, just uncheck all modules, emission and renderer especially, then when you select and simulate either particle system, the rest in the same object tree will simulate altogether.

1 Like

Ok thanks for the info ifurkend. Too bad it can’t be done. Maybe I can use shaders to move the shafts and other various elements rather than using the particle systems. But it might take more time than it’s worth.

FYI we have been working on a way to preview all systems in Edit Mode :slight_smile:

2 Likes

One option to achieve this is to write a script with the ExecuteInEditMode attribute on it. You can the call ParticleSystem.Simulate in that script.

Cool that’s nice :wink: I guess I’m doing something wrong in my script then.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class SimulateAllPS : MonoBehaviour
{
    private readonly List<ParticleSystem> AllParticleSystems = new List<ParticleSystem>();
    private float Timer;
    public float RefreshPsTime = 10f;
    public bool RefreshNow = true;

    void Start ()
    {
       Timer = 0f;
       AllParticleSystems.AddRange(FindObjectsOfType<ParticleSystem>());

       Debug.Log("Start");

       foreach (var ps in AllParticleSystems)
       {
           //if (ps.isStopped || ps.isPaused)
           ps.Simulate(0);

           Debug.Log("Simulating: " + ps);
       }
    }
  
    void Update ()
    {
        Debug.Log("Updating");

        if (RefreshNow)
        {
            AllParticleSystems.Clear();
            AllParticleSystems.AddRange(FindObjectsOfType<ParticleSystem>());

            foreach (var ps in AllParticleSystems)
            {
                if (ps.isStopped || ps.isPaused)
                    ps.Simulate(0);

                Debug.Log("Simulating: " + ps);
            }
        }

      

        //Timer += Time.deltaTime;
        //if (Timer > RefreshPsTime)
        //{
        //    AllParticleSystems.Clear();
          // AllParticleSystems.AddRange(FindObjectsOfType<ParticleSystem>());
        //}
    }
}

I tried a bunch of different ways but my PS are not simulating.

Check the params you are passing to Simulate. One is a “restart” bool. Make sure it’s false, and set the time param to Time.deltaTime.

Your script looks almost good though… I’m sure it’s nearly working!

3 Likes

Richard, are you sure this is supposed to work?
The particle system seem to advance 1 frame and then stop. We would need to call it every frame, but ExecuteInEditMode only call update when there is a scene change and in this case it gets called only once.
Anybody was able to make it work?
It would be very useful to preview particles all at once in the editor without selecting each.

I’m pretty sure it works… I know other developers who are using the technique successfully. Admittedly, I’m not sure about the update frequency of [ExecuteInEditMode] scripts though. Googling suggests you’re right about the update frequency, and some more googling suggests that this may work for you: https://answers.unity.com/questions/1006398/executeineditmode-than-runs-update-all-the-time.html

If/when you upgrade to 2017.3, you’ll notice a new option in the Scene View Overlay, called Simulate Layers. You can use this to get the preview behavior you want, without writing any custom scripts.

1 Like

Thank you very much! I am already on 2017.3 so I’ll use the latter.
I saw that option before but thought it was something for performance, some sort of particle culling.
Works beautifully now.

1 Like

Hi Richard, going back to this as I am trying to control particles manually in gameplay.
Is there any way to set the time of the particle emittter?
The time property doesn’t seem to work, it just continue to play.
And the simulate method seem to play all the particles up to the time given, there is no start time.
I am looking for something like Animator.StartPlayback.
You can seek in editor by moving the time slider, so I guess you have some way.

ps.Simulate(startTime, true, true);

ought to do it.

That will restart the system and play it up to the point you want.

If you want to be smarter for forwards scrubbing, you can detect that you’re going forwards, and avoid the restart, (set param 3 to false) and simply simulate forwards by newTime - ps.time.

1 Like

Doesn’t work. It seem to render few frames and rewind.
I found some code that set the randomseed property before simulating. If I do that, the parent emitter behave correctly, the child emitter still play when they shouldn’t.
Is it a bug? Do I need to set the randomseed of all the child systems?

I made a bug report(1010191).
After further digging it seem to make it work you need to set the randomseed property of all the ParticleSystem involved, including children.
I don’t think that is the expected behavior.

1 Like

I think it’s probably “by design”. I can see why it’s not ideal for you here though. The auto seed mode changes the seed on each restart. I suspect changing this behavior would cause problems for other users, so I think it must stay as it is.

As you have discovered, it’s simple to set a fixed seed to get the behavior you want (and you can always use a fresh seed in a situation where you do want it to trigger differently)

1 Like

I can’t find the Simulate Layers option, I’m on 2017.4.

Where is this option exactly?

Thanks

In the scene view, when playing a particle system in edit mode, there is a little dialog in the lower right corner with play/pause etc buttons in it. It’s on there. We may have renamed it after feedback… just to keep you guessing!!

1 Like

What have you renamed it to?
Will this simulate all of my particles in the scene?

I checked, Simulate Layers is the final name, any renaming must have happened earlier during internal testing.

All looping effects. And only if you set the layer mask to a value that encompasses all your particle systems.

Hopping on here to continue the conversation.

I’ve noticed this ‘Simulate Layers’ option, and it’s useful – but is there any way to set these layers through code?

For context: Our team’s toolset sidesteps default GameObject selection, so when using the tool, our artists are never actually selecting the Particle System. I’d like to set these Simulate Layers automatically when they open the tool.