Setting Random Seed to false in script

Hey, I’m all sorts of new to unity and coding, but I’ve been fiddling with particle systems.
I created a sub particle system on startup and tried to set the auto random seed to false, but the client gives me the following error:

Don’t set random seed while system is playing!
UnityEngine.ParticleSystem:set_randomSeed(UInt32)
ParticleLauncher:Start() (at Assets/ParticleLauncher.cs:75)

Here’s the code I’m using, setting the autorandom seed on line 23:

void Start()
    {
        curveNum = 0;
        angularCurveMod = 1;
        psTransfrom.Rotate(new Vector3(0, 0, 1), (arc / -2));

        if (enableSub)
        {
            Material particleMaterial = subMaterial;
            var subSystemGO = new GameObject("Particle System");
            var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>();
            var subMain = subParticleSystem.main;
            var subShape = subParticleSystem.shape;         
            var subEmission = subParticleSystem.emission;

         
            subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
            subMain.startColor = Color.red;
            subMain.startSize = subSize;
            subMain.startSpeed = subSpeed;
            subMain.startLifetime = subLifeTime;
            subMain.simulationSpace = ParticleSystemSimulationSpace.World;
            subParticleSystem.useAutoRandomSeed = false;  //<- setting the random seed to false
            subShape.shapeType = ParticleSystemShapeType.Circle;
            subShape.arc = subArc;
            subEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, subNumOfParticles) });

            subSystemGO.transform.SetParent(particleLauncher.transform);
            subSystemGO.transform.Rotate(new Vector3(0, 0, 1), (subArc / 2));
            var subModule = particleLauncher.subEmitters;
            subModule.enabled = true;
            subModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritColor);
         
         

        }
   
    }

I’ve also tried it with subParticleSystem.randomSeed =, but it returns the same error.

First time posting so if anything is weird let me know.

Well, seems it doesn’t want you to change the seed while the particles are simulating. I may move that feature to the beginning and maybe try something like:

yourParticleS.Stop(true);
yourParticleS.useAutoRandomSeed = false;
yourParticleS.Simulate(0, true, true);

to make sure that you’r not changing the seed during the sim.

Hey! Huge thanks for your reply, got the error to clear.

However, it’s still not listening to useAutoRandomSeed = false, or randomSeed =. The code is listening to other changes inside the stop - simulate. Really stumped here.

new code, relevant lines are 10, 12 and 21:

 if (enableSub)
        {
            Material particleMaterial = subMaterial;
            var subSystemGO = new GameObject("Particle System");
            var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>();
            var subMain = subParticleSystem.main;
            var subShape = subParticleSystem.shape;          
            var subEmission = subParticleSystem.emission;

            subParticleSystem.Stop(true);         // stopping the simulation             
            subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
            subParticleSystem.useAutoRandomSeed = false;    //setting the random seed to false
            subMain.startColor = Color.red;
            subMain.startSize = subSize;
            subMain.startSpeed = subSpeed;
            subMain.startLifetime = subLifeTime;
            subMain.simulationSpace = ParticleSystemSimulationSpace.World;         
            subShape.shapeType = ParticleSystemShapeType.Circle;
            subShape.arc = subArc;
            subEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, subNumOfParticles) });
            subParticleSystem.Simulate(0, true, true);        //restarting the system


            subSystemGO.transform.SetParent(particleLauncher.transform);
            subSystemGO.transform.Rotate(new Vector3(0, 0, 1), (subArc / 2));
            var subModule = particleLauncher.subEmitters;
            subModule.enabled = true;
            subModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritColor);
          
          
          

        }

Again, thank you for bearing with me.

Hey, found what was wrong.

If you want to disable the randomness you don’t need to touch the Random Seed module.
just set the ParticleSystemShapeMultiModeValue to for example .burstSpread. You don’t have to stop particle system either and the particles come out nice and clean now.

Here’s the working code:

        if (enableSub)
        {
            Material particleMaterial = subMaterial;
            var subSystemGO = new GameObject("Particle System");
            var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>();
            var subMain = subParticleSystem.main;
            var subShape = subParticleSystem.shape;           
            var subEmission = subParticleSystem.emission;
            var subMode = ParticleSystemShapeMultiModeValue.BurstSpread;  // setting up a variable to change modes
                               
            subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial;         
            subMain.startColor = Color.red;
            subMain.startSize = subSize;
            subMain.startSpeed = subSpeed;
            subMain.startLifetime = subLifeTime;
            subMain.simulationSpace = ParticleSystemSimulationSpace.World;          
            subShape.shapeType = ParticleSystemShapeType.Circle;
            subShape.arc = subArc;
            subShape.arcMode = subMode;     // setting the arcMode from random to burst spread
            subEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, subNumOfParticles) });        

            subSystemGO.transform.SetParent(particleLauncher.transform);
            subSystemGO.transform.Rotate(new Vector3(0, 0, 1), (subArc / 2));
            var subModule = particleLauncher.subEmitters;
            subModule.enabled = true;
            subModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritColor);
           
           
           

        }

great!