- Home /
How to destroy an instantiated prefab object and keep instantiating it
Hello, I'm woking on a game similar to Temple Run and I'm spawning (instantiating prefabs) all the platforms randomly to create the way for the run. After the player has passed a platform I need to destroy that platform but I don't know how to do it... I tryed putting a box collider over the platform and attach to the platform a script with a OnTriggerExit void to destroy the platform when the player exit the trigger... but then I get an error that says:
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.
I searched a lot in the forum and with Google for a solution but I didn't find anything... any help would be highly appreciated. Thanks
Hi, thx for your reply, I was using Destroy(myPlatform), anyway I've resolved everything using object pooling ins$$anonymous$$d.
Hi, thx for your reply, I was using Destroy(myPlatform), anyway I've resolved everything using object pooling ins$$anonymous$$d.
Answer by AlasdairHendry · Aug 11, 2017 at 03:37 PM
Are you using a List to store the Platforms? If so, you might be deleting the gameobject, but not removing it from the list, and the list is still trying to access it somehow
Hi, thanks a lot for your reply, I've already resolved everything using object pooling... Ciao and thx.
Your answer
Follow this Question
Related Questions
Instantiate 1 object after 2 objects collide. ( C# ) 1 Answer
walk through an object once 0 Answers
Destroying childs and Instantiate [C#] 0 Answers
Destroy temp object and make new object. 0 Answers
I can't get 2DCollider to work. 1 Answer