Question by 
               unity_smoUx44e2lP0cQ · Mar 08 at 03:49 PM · 
                editordestroydestroyimmediate  
              
 
              How to properly use both Destroy and DestroyImmediate for mixed editor/game code
Hi,
I'm new here so I hope I'll make myself clear... I have an algorithm (re)generating a mesh which is called both in game and in editor.
To save memory, I split the mesh into chunks, which I destroy when I don't need them anymore. To do this, I have something like this :
 if (Application.isPlaying)
 {
     Destroy(holderTransform.gameObject);
 }
 else
 {
     DestroyImmediate(holderTransform.gameObject);
 }
The thing is DestroyImmediate "is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate", which happens in editor mode.
But what should I do then, as the Destroy method isn't available in editor ?
Thanks for your ideas !
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                