Best way to spread particle system?

Hello,

I am currently working on propagation of fire and therefore I am not completely sure, if there are multiple or better ways of making Particle Effect spread instead of Instantiate().

My current way of thinking, is that I have central point of my fire, and it makes new fire instances over time in random way away from the central point. It looks cool, but it is really costly… My PC cannot maintain to run with 20+ Particle Systems cloned, even if I make them less detailed (for example making max of 10 particles/each system).

How can I achieve a optimization for this? Maybe there is another way of spreading this?

Any help would do.

    private void FixedUpdate()
    {
        if(Time.fixedTime % .5 == 0 && Time.fixedTime < 5)
        {
            CloneFire();
        }
    }

    void CloneFire ()
    {
        Vector3 newFirePos = new Vector3(newFireX + Random.Range(1f, -1f)*Time.fixedTime*2, 0.2f, newFireZ + Random.Range(1f, -1f) * Time.fixedTime*2);
        fireClone = Instantiate(fireStarter, newFirePos, Quaternion.identity) as GameObject;
    }

I didn’t try it, but under “Shape” in the particle system you can select a mesh as the source of your particles.

Create a custom mesh and add it to your particle system. To make the fire spread you add more vertices and triangles to the mesh.

I’m not sure if it’s necessary, but I had problems with changing a mesh after it was assigned to a mesh collider. If it looks like the mesh isn’t updated in your particle system try to reasign the mesh to the particle system after every change to it.

And your Time.fixedTime % .5 == 0could cause some problems. Time.fixedTime is a float value and comparing float values (float % float is still float) with == is always a bad practice. It’s alsways a bad practice because of rounding errors, but in this case Time.fixedTime gives you the time of the current frame. So you’re relying on one frame hitting exactly a value like 2.5. But it probably would hit something like 2.465456645 or 2.5643453534. And 2.5 == 2.465456645 is false. It’s close but for a computer it’s still false. I’m really surprised you did see some fire att all.

If you want to do something every x seconds use this instead: Unity - Scripting API: MonoBehaviour.InvokeRepeating
And if the function shouldn’t be called forever use a counter in the function and when it reached its maximum value (or another condition is true) call this function: Unity - Scripting API: MonoBehaviour.StopCoroutine