MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Hello everybody im currently new to developing games and i find errors saying
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. ObjectPooler.GetPooledObject () (at Assets/Scripts/ObjectPooler.cs:31) PlatformGenerator.Update () (at Assets/Scripts/PlatformGenerator.cs:57)
this i attached together part of the codes
PlayerGenerator
GameObject newPlatform = theObjectPools[platformSelector].GetPooledObject();
newPlatform.transform.position = transform.position;
newPlatform.transform.rotation = transform.rotation;
newPlatform.SetActive(true);
transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2), transform.position.y, transform.position.z);
ObjectPooler
public GameObject GetPooledObject() { for (int i = 0; i < pooledObjects.Count; i++) { if (!pooledObjects[i].activeInHierarchy) { return pooledObjects[i]; } }
GameObject obj = (GameObject)Instantiate(pooledObject);
obj.SetActive(false);
pooledObjects.Add(obj);
return obj;
Help me out pls your help is very much appreciated Thank you so much xx
Do you ever destroy the pooled objects instead of disabling them?
And please, edit your question and provide your code AS TEXT.
What do you mean with your question? i dont get it. Can you explain to me?
ive edited the text. Can you help me please thank you xx