ParticleSystem.SetParticles() does nothing

Hi, i’m working on a procedural land generation, and to display the grass, I would like to use ParticleSystem. I’ve searched in every API docs and I can’t figure out why my code would not work with the ParticleSystem.SetParticles() function.

private void SetGrassParticleSystem()
        ParticleSystem ps = transform.gameObject.AddComponent<ParticleSystem>();
        ps.maxParticles = nodes.Count; // = 2601
        ps.startSpeed = 0;
        ps.startLifetime = float.PositiveInfinity;
        ps.enableEmission = false;

        ParticleSystem.ShapeModule shape = ps.shape;
        shape.shapeType = ParticleSystemShapeType.Sphere;
        shape.radius = 100;

        ParticleSystemRenderer psr = ps.GetComponent<ParticleSystemRenderer>();
        psr.material = SkinBank.GrassMat();

        ParticleSystem.Particle[] particles = new ParticleSystem.Particle[nodes.Count];
        int i = 0;
        foreach(Node node in nodes.Values)
            particles *= new ParticleSystem.Particle();*

particles*.position = node.Position();*
particles*.startSize = 1;*
particles*.startColor = new Color32(1, 1, 1, 1);*


ps.SetParticles(particles, particles.Length, 0);

The thing to keep in mind is that all default values for newly constructed ParticleSystem.Particle are zero. You have to set both remainingLifetime and startLifetime to some high value. I wish they mentioned this in the docs.

I had this problem in 2022.2.9f1…

If you’re creating the particle system via script you can’t make the particle system AND set the particles at the same time. You need to run one after the other.

For example

  • Create your particle system in start and set all it’s settings
  • Then call .setparticles in update


  • Make an enumerator and write “yield return null” after you have instantiated the particle system and before you call .setparticles