Hello, thx for helping me.
so i want to instantiate some game object, and those game object have children and those children also have children… it’s a complexe 3D model.
and i want to stock the color of each element in a list so i can modify the model color and re apply the base color when i want.
so it’s 2 scryptes, the first one run fine and do what’s is supposed to do :
private void OnMouseUpAsButton()
{
if (Data.GetComponent<DataCtrl>().isbuilding == false)
{
foreach (GameObject t in batiments)
{
if (t.name == bouton && batiment == null)
{
batiment = PhotonNetwork.Instantiate((racename + "bat/bat/" + t.name), mousepos, new Quaternion(0, 0, 0, 0), 0).transform;
Data.GetComponent<DataCtrl>().isbuilding = true;
if (batiment.gameObject.GetComponent<Renderer>() != null)
{
basecolor = batiment.gameObject.GetComponent<Renderer>().material.color;
}
else
{
multibasecolor = null;
getmulticolor(batiment);
}
}
}
}
}
and the second one who give the weird error is get multicolor ofcourse
void getmulticolor(Transform bbatiment)
{
Debug.Log("niveau 1" + bbatiment.gameObject.name);
foreach (Transform h in bbatiment)
{
if (h.GetComponent<Renderer>() != null)
{
Debug.Log("niveau 2" + h.gameObject.name);
multibasecolor.Add(h.gameObject.GetComponent<Renderer>().material.color);
}
else
{
getmulticolor(h);
}
}
}
what is realy weird is that what give the error is this line
multibasecolor.Add(h.gameObject.GetComponent<Renderer>().material.color);
and the error is object reference is not set to an instance of an object… but the if detect that the renderer existe !! and say the right name in the debug.log niveau 2 so why can’t he find the object…
i’ve try adding and removing .gameObject. it doesn’t change anything.
and what is even weirder is that i have this code also in the script and this one works fine too :
if (batiment != null)
{
applycolor(batiment, valid ? Color.green : Color.red);
}
void applycolor(Transform batiment, Color couleur)
{
if (batiment.gameObject.GetComponent<Renderer>() != null)
{
batiment.gameObject.GetComponent<Renderer>().material.color = couleur;
}
else
{
foreach (Transform h in batiment)
{
applycolor(h, couleur);
}
}
}