- Home /
NullReferenceException when trying to access other GO in script. C#
Hello guys i've been going crazy for the past few hours trying to figure out what i could possibly be doing wrong. I have a fair bit of knowledge in both c# and unity's librarys. What my method is doing is scanning a List to and accesses the particular country gameobject. After the GO(gameobject) is found it scans the scripts list of objects(Tagobjects). I then attempt to access the GO's bool variable,however i get a error once i try to read the proviencewindowdisplay script in the gameobject.
foreach(Country country in EnemyCountrysList)//accessing country objects in list
{
Country tempcountryinstance = country.GetComponent<Country>();
foreach(GameObject GO in tempcountryinstance.TagObjects)
{
ProvienceWindowDisplay display = GO.GetComponent<ProvienceWindowDisplay>();//display gets component data for Specific GO
if(display.BorderProvience)//NULLREFERENCEEXCEPTION HERE
{
if(tempcounter == 0)
{
BorderProviencesList1.Add(GO);
}
if(tempcounter == 1)
{
BorderProviencesList2.Add(GO);
}
}
}
tempcounter++; //temp counter increment cause a new list to be populated with a different country instances proviences
}
Answer by citizen_rafiq · Aug 30, 2013 at 04:00 PM
cause of this problem No ProvienceWindowDisplay component attached with object.
if attached then soln is:
if(display&&display.BorderProvience) { // good luck }
Your answer
Follow this Question
Related Questions
NullReferenceException with GetComponent() C# 0 Answers
Object reference not set to an instance of an object in c#. 0 Answers
Has my project's data corrupted? Script keeps returning null but 20 minutes ago it wasn't? 1 Answer
I'm having more problems accessing a variable from another script in c# 2 Answers
Multiple Cars not working 1 Answer