Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kinetifex on June 17, 2013, 03:56:59 PM

Title: Bug: Editor DestroyImmediate?
Post by: kinetifex on June 17, 2013, 03:56:59 PM
In the Unity Editor, NGUI elements are not being hidden properly and would not be destroyed even between play sessions. I'm getting the following error related to a triggered event call:

Quote
Destroying GameObjects immediately is not permitted during physics trigger/contact or animation event callbacks. You must use Destroy instead.
UnityEngine.Object:DestroyImmediate(Object)
NGUITools:DestroyImmediate(Object) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:514)

Looking at line 514 in NGUITools, if the Application isEditor, then UnityEngine.Object.DestroyImmediate is called.

Changing this to always call:
  1. UnityEngine.Object.Destroy(obj);
seems to fix the error.

Any reason DestroyImmediate was being called? Can this be fixed in the next version?

Thanks!
Title: Re: Bug: Editor DestroyImmediate?
Post by: Nicki on June 17, 2013, 05:58:00 PM
Don't destroy remove widgets or panels from animation callbacks or physics triggers. :)

You can delay it by doing this

  1. //where you would normally trigger your removal:
  2. StartCoroutine(MyDestroyerMethod);
  3.  
  4.  
  5. IEnumerator MyDestryerMethod()
  6. {
  7. yield return null;
  8. //Do the disable call that triggers the problem.
  9. }
  10.  

The DestroyImmediate is used because it will cause problems in the Editor otherwise, as far as I know. You'll have to ask ArenMook about that.
Title: Re: Bug: Editor DestroyImmediate?
Post by: ArenMook on June 17, 2013, 09:23:09 PM
Yeah, UnityEngine.Object.Destroy(obj); doesn't work in the editor.
Title: Re: Bug: Editor DestroyImmediate?
Post by: kinetifex on June 18, 2013, 01:59:35 PM
Ok, switching to UnityEngine.Object.Destroy(obj); seemed to fix this issue fine for me in the Editor, so I'm not sure why you wouldn't use that?

However, delaying with a co-routine is working, too so I'll just run with that.

Thanks.
Title: Re: Bug: Editor DestroyImmediate?
Post by: ArenMook on June 18, 2013, 02:08:53 PM
Unhide the hidden game objects by selecting "geometry" debugging on the panels. You will notice that using UnityEngine.Object.Destroy they never go away after play/stop -- they just keep piling up.