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

Weird error in a grid snapping script

Discussion in 'Scripting' started by kaarme, Nov 2, 2014.

  1. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Last edited: Nov 5, 2014
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    GridCube is most likely null.
     
  3. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    That's why this is so wierd. It is not null.
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Hm. Peculiar. Not entirely sure. If you are simply adding an object to a list, it should not be an issue if the object is properly assigned. You did a check...

    ... At line 92, just prior,
    Code (csharp):
    1.  
    2. print("gridCube " + gridCube);
    See if this reports an object.
     
  5. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Code (CSharp):
    1. gridCube gridCube(Clone) (UnityEngine.GameObject)
    2. UnityEngine.MonoBehaviour:print(Object)
    3. GridController:snapPoint(GameObject) (at Assets/Game_scripts/GridController.cs:92)
    4. BuildScript:FixedUpdate() (at Assets/Game_scripts/BuildScript.cs:69)
    I posted as c# code because of smileys.
     
    Last edited: Nov 3, 2014
  6. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Bumb.
     
  7. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    So gridCube exists? it is assigned?
     
  8. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    If it returns a GameObject I guess so.
     
  9. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Unsure man.
     
  10. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Well I don't understand how it could return a value if it isn't assigned.
     
  11. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    So you continue to get the same error?
     
  12. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Line 92 would throw that error if the list was null - which you set it to in Clear() so my guess is you're calling Clear and then trying to call snapPoint aftewards without re-initializing the list.

    @renman3000 - gridCube can be null. Adding null to a list is allowed.
     
    renman3000 likes this.
  13. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Yes, it doesn't throw that error anymore after commenting use of the Clear function.
    Thank you so much, now I think I can fix it.
     
    renman3000 likes this.
  14. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177