- Home /
Question by
VladNeykov · Jan 01, 2014 at 05:02 PM ·
listclassstatic
Static GameObject List gives error when calling Add or Count from another script
Hi gang! I have a list in one of my classes and am trying to access it from another script, however I receive an error when I try to use Add or Count.
Class with list:
static class Recycler
{
static var myList: List.<GameObject>;
}
Accessing list from another script:
var listLength = Recycler.myList.Count; //NullReferenceException error
Recycler.myList.Add(gameObject); //NullReferenceException error
I have no problem accessing static variables(float, int, etc.) in the same scenario. Is there something special I need to know when dealing with lists in this way?
Thank you in advance!
Vlad
Comment
Best Answer
Answer by HappyMoo · Jan 01, 2014 at 05:48 PM
I don't know the javascript syntax, but you're not creating the list...
static var myList: List.<GameObject> = new List.<GameObject>();
Your answer
Follow this Question
Related Questions
Static class member for offset 1 Answer
A node in a childnode? 1 Answer
JS Class "Does not denote valid type" 0 Answers
Foreach - what am I doing wrong? 1 Answer