- Home /
MissingReferenceException
i have i iceball hitting a paddle then that paddle is surrounded with ice, when i tap the ice it will break and i can move the paddle again.
now, when i start the game it works the 1st time, the 2nd time i get this error : MissingReferenceException: The object of type 'iceCube1' 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.
and the ice cube stays visibble, the cube can't be broken and the paddle can't be moved.
i know it has to do with "Destroy" i tried gameObject.active=false; but somehow the paddle won't move after breaking the icecube.
i have uploaded the snippets here : Iceball :
http://codeviewer.org/view/code:300a
iceCube :
Answer by GC1983 · Feb 26, 2013 at 05:47 PM
So, the only thing thats breaking and destroying is the IceCube, right? Well, obviously you have destroyed the object you want to reference. doing gameObject.active = false also will turn off any source of recognition that the object is still there. So any scripts that is searching for it, wont find it. Trying gameObject.renderer.enabled = true/false. That just turns off the mesh and keeps the object active.
this works thx. how can i best change the instantiate line (43&53) in the Iceball script? i made already an if GameObject exists for it
i'm still kinda new @ this :)
Youre going to place the icecube object into the scene before game play. Place it exactly where you would instantiate it. $$anonymous$$ake sure the renderer is turned off so it cant be seen. And then call gameObject.renderer.enabled = true where you would call the instantiate.
hmm.. can't do that because the paddle is moving and should be trapped in the icecube on the position it got hit by the iceball
Sure, just attach the hidden object to the paddle. The icecube will be the child object of the paddle. Then relocate it where you want. So it will move with the paddle and when you enabled the renderer when the snowball hits the paddle, it will appear right where you would have instantiated on the paddle.
Your answer
Follow this Question
Related Questions
How To Keep GameObjects From Enabling Again? 2 Answers
Destroy and instantiate far objects 2 Answers
Button to create object??? 1 Answer
Active Prefabs 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers