- Home /
Accessing a MonoBehaviour List within a Non-MonoBehaviour Script
So, the issue I have is I am trying to access a List that has all of my virtual keys on a virtual keyboard stored in a list, but it's giving me an error. This list is attached to a MonoBehaviour script which is attached to a gameobject within my game. I guess, and I assume that there is a logical explanation, I can't access a predetermined list from a non-MonoBehaviour Script. So do I need to add all of my buttons for my keyboard in the script instead of the inspector? Or, am I just doing something wrong? Thank you!
ERROR: Error code: NullReferenceException: Object reference not set to an instance of an object <-- This is because I am calling a MonoBehaviour from a non-MonoBehaviour so there's no way for me to reference it, which is my question.
CODE: inputDict.Add("moveForward", new Inputs("W", "moveForward", allKeys.allKeys[2]));
The "allKeys" part is the part discussed above. I don't believe code is needed for this question as it is more of just a general question, but here you go.
Show some code please. I don't really understand what your setup is and what is the problem. Also if you get an error, it would make sense to tell us what the error is.
Answer by WaterMinecraft · Jul 26, 2015 at 01:36 PM
For those interested, I was unable to create the object in my non-MonoBehvaiour script, so I ended up creating a method, passing in my list through there and distributing the list through arguments for each method in the non-MonoBehvaiour. For more explanation you can comment! Thanks!
Answer by termovent · Jul 26, 2015 at 01:45 PM
well read the error carefully, are you creating the non mono object?
are you sure you are doing something like var obj=new NonMono();?
Actually, I was trying to create a monoobject (: which is why it didn't work, I just had to think a little more about it. Thank you!