- Home /
 
The question is answered, right answer was accepted
Unity createNew Game Object after calling a Destroy()
Hello all,
I'm having a weird issue with unity. When destroying GameObjects Unity creates a "New Game Object" GameObject into the outliner when the game is still running.
Here is my destroy call :
 private void DestroyBlock()
     {
        if (this.gameObject.transform.parent.gameObject)
         {
             gameController.RemoveBlockInMap(id);
             Destroy(this.gameObject.transform.parent.gameObject);
         }
     }
 
     void FixedUpdate () {
         if (blockCountAround != 8) {
           Invoke("DestroyBlock", lifeDuration);
         }
         else
         {
             CancelInvoke("DestroyBlock");
         }
         transform.Rotate(0.0f, Time.deltaTime * rotationSpeed, 0.0f);
     }
 
               Here is the problem ingame : 
Each time I destroy a GameObject "PRE_BlockCoin" Unity creates me a "New Game Object".
Thanks,
Could it be caused by the "CancelInvoke" ? I would leave some debug code in there to see if its canceling the destroy method.
I does. As the blockCountArount value is always different during the course of the game.
Answer by hexagonius · Dec 17, 2018 at 08:12 AM
does the console print anything? I suspect RemoveBlockInMap is creating it.
Nothing, I will try to look more into RemoveBlockIn$$anonymous$$ap
It was indeed the source of the issue. I was creating a new GameObject inside the function to hold the value and delete the gameobject in the list at the end.
Follow this Question
Related Questions
Script doesn't work anymore! 2 Answers
How do I Destroy a Child after Instantiating it? 1 Answer
Destroy Objects after a set time 2 Answers
transferring variables between scripts c# 3 Answers
Destroying Assests Not Permitted 1 Answer