Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question ArgumentNullException: Value cannot be null. Parameter name: particles

Discussion in 'Documentation' started by Benj1_, Apr 8, 2021.

  1. Benj1_

    Benj1_

    Joined:
    Aug 26, 2020
    Posts:
    1
    So I've been trying to solve this issue for a few hours.

    I'm doing a project in which we use multiple liquids, so of course I'm using the particle system
    The code works with liquid A but when attempting the same with liquid B i get the error:

    ArgumentNullException: Value cannot be null.
    Parameter name: particles
    UnityEngine.ParticleSystem.GetParticles (UnityEngine.ParticleSystem+Particle[] particles, System.Int32 size) (at <7597b2c734e642889083819df22da57c>:0)
    UnityEngine.ParticleSystem.GetParticles (UnityEngine.ParticleSystem+Particle[] particles) (at <7597b2c734e642889083819df22da57c>:0)
    testing.Update () (at Assets/Scripts/testing.cs:66)

    The declarations:
    Code (CSharp):
    1.     public class liquidHandler : MonoBehaviour
    2. {
    3.     public ParticleSystem H2O;
    4.     public ParticleSystem Acid;
    5.  
    6.     private ParticleSystem.Particle[] H2OParticles;
    7.     private ParticleSystem.Particle[] AcidParticles;
    The erroring code:
    Code (CSharp):
    1. //Checks for H2O in flask
    2.             int numH2OPart = H2O.GetParticles(H2OParticles);
    3.             for (int i = 0; i < numH2OPart; i++)
    4.             {
    5.                 if ((RbPos - H2OParticles[i].position).x < toll &&
    6.                  (RbPos - H2OParticles[i].position).y < toll && (RbPos
    7.                   - H2OParticles[i].position).z < toll)
    8.                 {
    9.                     H2oInFlask = true;
    10.                     Debug.Log(H2oInFlask);
    11.                 }
    12.             }
    13.             //Checks for acid in flask
    14.             int numAcidPart = H2O.GetParticles(AcidParticles); //Error here
    15.             for (int i = 0; i < numAcidPart; i++)
    16.             {
    17.                 if ((RbPos - AcidParticles[i].position).x < toll &&
    18.                 (RbPos - AcidParticles[i].position).y < toll && (RbPos
    19.                  - AcidParticles[i].position).z < toll)
    20.                 {
    21.                     AcidInFlask = true;
    22.                     Debug.Log(AcidInFlask);
    23.                 }
    Both liquids are in place in the inspector, any help is appreciated :)
     
  2. TaskerSama

    TaskerSama

    Joined:
    Jan 15, 2023
    Posts:
    2
    Had this problem too...