- Home /
gameobject has been destroyed you are still trying to access it
im getting this message and im sure its because when my player gets hit he loses all his gems, the gems flash and then there destroyed, following this message i get an odd message about matrix stack full depth reached but i cant see how theyre related, any how im instantiating a prefab making it flash using materials for a couple seconds and then destroying themso my error is because the flashing is still happening after there destroyed but i am already checking if the gameobject is null can anybody give me a hand? here is half the code to make the gems flash
void coinFlash()
{
newCoins = GameObject.FindGameObjectsWithTag("newcoins");
if (newCoins != null)
{
for (var i = 0; i < newCoins.Length; i++)
{
//coinPrefab.GetComponent<Renderer>().sharedMaterial.color = new Color32(250, 250, 210, 0);
coinPrefab.GetComponent<Renderer>().sharedMaterial = goldtrans;
}
}
}
Answer by taxvi · Feb 19, 2016 at 01:16 PM
I'm pretty sure that in worst case FindGameObjectsWithTag()
will return an empty array instead of null
. Anyways, to make double sure replace your 4th line with this:
if (newCoins != null || newCoins.Length > 0)
Your answer
Follow this Question
Related Questions
Why my object is ''destroyed'' when it's actually still in the scene? 0 Answers
Best practice handling deleted object refences during SceneManager.LoadScene 0 Answers
I have an error, script should check for null or not destroy game objects 2 Answers
null and Null isnt the same? 0 Answers
how to check for GameObject is null in array with random 1 Answer