Bug in Unity 2019.1 & Unity 2019.2, decreasing max particle count in Shuriken crashes Unity

Hi,

I try to set the max particles value in a particle in code and causes Unity to crash randomly, sometimes immediately, other times after a few changes to the value, but always crashes.

Is this a known bug ?

I use Unity 2019.1.3f1 (64-bit), same happen in user of my system in 2019.1.9f1 as well.

Thanks

What code do you use to set the max particles value?

1 Like

Thanks for reply, i use the following, but i tried also just set to a value and got stuck. Seems get stuck if set the value many times in general (no matter what value i put, or if move lower or higher)

It is also random, sometimes stuck after only 3-4 frames, other times after 50 frames for example, also got an out of memory message a few of the times got stuck.

My guess is the system gets recreated without releasing allocations each time max particles are redefined and runs out of memory at some point. This code works fine in Unity 2018.

ParticleSystem.MainModule MainMod = ParticleSystem.main;
MainMod.maxParticles = MainMod.maxParticles-rate;

Have you used this script in other projects and other version of Unity? Did it work?

Yes, works fine in Unity 2018, there was no issue at all.

Also “MainMod.maxParticles” is a settable variable, so should not crash Unity for setting it in any case.

If it worked in 2018, it might be a bug with 2019. Maybe you should file a report?

As for me, I tried the following script on a particle system of my own. It works and Unity (2019.1.11f1) didn’t crash. If it can inspire you, be my guest. :slight_smile:

using UnityEngine;

public class MaxParticlesSettings : MonoBehaviour
{
    private ParticleSystem particles;
    private int[] maxParticlesToEmit = new int[] { 500, 1000, 1500 };
    int index;

    private void Start()
    {
        particles = GetComponent<ParticleSystem>();
        index = Random.Range(0, maxParticlesToEmit.Length);
}

    private void Update()
    {
        ParticleSystem.MainModule main = particles.main;
        main.maxParticles = maxParticlesToEmit[index];
    }
}

Thanks for the heads up, i will test in 2019.1.11f1 too, as may have been fixed in one version after 2019.1.9f1 and move from there.

Another script:

using UnityEngine;

public class MaxParticlesSettings : MonoBehaviour
{
    private ParticleSystem particles;
    private const int minLevelParticles = 250;
    private const int maxLevelParticles = 1000;
    private int levelParticles;

    private void Start()
    {
        particles = GetComponent<ParticleSystem>();
        levelParticles = Random.Range(minLevelParticles, maxLevelParticles);

        ParticleSystem.MainModule main = particles.main;
        main.maxParticles = levelParticles;
    }
}
1 Like

Hi,
I eventually tried this script on a new particle and crashes

using UnityEngine;
public class testParticles : MonoBehaviour
{
    private ParticleSystem particles;
    private int[] maxParticlesToEmit = new int[] { 500, 1000, 1500 };
    int index;
    private void Start()
    {
        particles = GetComponent<ParticleSystem>();
        index = Random.Range(0, maxParticlesToEmit.Length);
        ParticleSystem.MainModule main = particles.main;
        main.maxParticles = maxParticlesToEmit[index];
    }
    private void Update()
    {
        index = Random.Range(0, maxParticlesToEmit.Length);
        ParticleSystem.MainModule main = particles.main;
        //main.maxParticles = maxParticlesToEmit[index];
        main.maxParticles = main.maxParticles - 1;
    }
}

The crash is not instant, will take a bit time as it goes down in particle count, but eventually will crash

Thanks for all the input :slight_smile:

UPDATE:

I eventually found the exact bug, is not about decrease max particle count, but about doing it when world Collisions in 3D are enabled, then crashes with 100% probability.

I attach a mini project that replicates, happens in all Unity 2019 versions (latest too)

I hope it gets resolved soon.

BUG REPORT
(Case 1177914) Particle system crash in all Unity 2019 versions, when 3D world collisions active & decrease max particle count

1 Like

I still get this issue, though now the simple case i made works in latest Unity 2019.2, but in my project still crashes and cannot figure out why, in Unity 2019.2.

Any news on final fix for this ?

It is happening when change max particle count and 3D collisions are on.

I think this time has to do with the subemitters i use, when disable them is working without crash (but of course not as expected, as need to connect to subemitters).

It works just by disable sub emitters in the main regulated particle, subemitters are still active.

In my experience, the build made with Unity 2019.4 crashes on some (not all) android devices even without 3D world collision enabled. To avoid the crash, I had to increase the number of max particles from 300 to 800 (not sure which is the minimum value) . Hope this bug has been fixed in more recent version of Unity.

1 Like