Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

3D Graphs in Unity

Discussion in 'Scripting' started by etchthaboss, Jan 13, 2017.

  1. etchthaboss

    etchthaboss

    Joined:
    Jun 13, 2016
    Posts:
    12
    Hey folks,

    I'm trying to follow CatlikeCoding's tutorial on 3d graphs in unity. However seems that some features are deprecated. Disclaimer: I'm not terribly experienced with unity. Here's the tutorial: http://catlikecoding.com/unity/tutorials/graphs/#a-questionmark

    Rn i'm at this step of her tutorial:

    Code (CSharp):
    1. void Start () {
    2.  
    3.  
    4.         if (resolution < 10 || resolution > 100) {
    5.             Debug.LogWarning ("Grapher resolution is out of bounds, resetting to minimum.", this);
    6.             resolution = 10;
    7.        
    8.             float increment = 1f / (resolution - 1);
    9.             for (int i = 0; i < resolution; i++) {
    10.                 float x = i * increment;
    11.                 points [i].position = new Vector3 (x, 0f, 0f);
    12.                 points [i].color = new Color (x, 0f, 0f);
    13.                 points [i].size = 0.1f;
    14.  
    15.             }
    16.             points = new ParticleSystem.Particle[resolution];
    17.  
    18.         }
    19.     }
    20.     // Update is called once per frame
    21.     void Update () {
    22.         particleSystem.SetParticles(points, points.Length);
    23.  
    24.  
    25.     }
    26. }
    27.  
    My error is at the line inside of Update(). This is deprecated. So i replaced it by doing:

    particles = GetComponent <ParticleSystem> ();
    (inside of Start)

    Then in update i used: particles.SetParticles(points, points.Length);

    However i'm getting an object reference not set to an instance of object error pointing to my Update function. Any help would be appreciated.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
  3. etchthaboss

    etchthaboss

    Joined:
    Jun 13, 2016
    Posts:
    12
    So i've got
    Code (CSharp):
    1. public ParticleSystem particleSystem;
    at the top before start.

    Then inside of start I have:
    Code (CSharp):
    1. particleSystem = GetComponent<ParticleSystem>();
    then in Update I have:
    Code (CSharp):
    1. particleSystem.SetParticles(points, points.Length);
    It's still throwing the null reference error at the last line in Update.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Sounds like the script is not attached to a particle system game object. Instead of doing get component drag the particle system into the slot in the inspector.
     
  5. etchthaboss

    etchthaboss

    Joined:
    Jun 13, 2016
    Posts:
    12
    Hmm, it is infact attached to the particle system. I created the component within the particle and it shows up in the inspector.