Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Dune on October 29, 2016, 12:57:29 AM

Title: Bug - UpdateAnchors called on object after OnDestroy
Post by: Dune on October 29, 2016, 12:57:29 AM
This may be a Unity bug, but I thought I should post it here since I'm finding it while working on a custom NGUI class.

A problem is arising after the object is destroyed. OnDestroy() is called, and then another UpdateAnchors()

I cannot use a flag in OnDestroy, because after the OnDestroy is called, all the values for the object are reset.

Here's a simple class to test this.
  1. public class testCallOrder : MonoBehaviour
  2. {
  3.     void Awake()
  4.     {
  5.         Debug.Log("Awake");
  6.     }
  7.  
  8.     void Start()
  9.     {
  10.         Debug.Log("Start");
  11.     }
  12.  
  13.     void OnDestroy()
  14.     {
  15.         Debug.Log("OnDestroy");
  16.     }
  17.  
  18.     public void UpdateAnchors()
  19.     {
  20.         Debug.Log("UpdateAnchors");
  21.     }
  22. }
  23.  

Put this in a NGUI sprite, run the game. Expand the game window to maximum, then quit the game.
Title: Re: Bug - UpdateAnchors called on object after OnDestroy
Post by: ArenMook on October 30, 2016, 12:42:37 PM
I'm not getting this on my end... what does the call stack look like for your UpdateAnchors call?

P.S. note that you need to add [ExecuteInEditMode] to this script. UpdateAnchors is an NGUI call that's meant to be called on scripts that are executable during edit mode as well.
  1. [ExecuteInEditMode]
  2. public class testCallOrder : MonoBehaviour
  3. ...
Title: Re: Bug - UpdateAnchors called on object after OnDestroy
Post by: Dune on October 30, 2016, 03:06:44 PM
The call-stack is:

>   Void SeaRisen.testCallOrder:UpdateAnchors ()+0x0 at C:\Users\Chuck\Desktop\_Unity\Projects\Game\Demo1\Assets\testCallOrder.cs:32   C#
    Void UnityEngine.Component:BroadcastMessage (String, SendMessageOptions)+0x4 at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineComponentBindings.gen.cs:255   C#
    Void UIRoot:UpdateScale (Boolean)+0xa0 at C:\Users\Chuck\Desktop\_Unity\Projects\Game\Demo1\Assets\NGUI\Scripts\UI\UIRoot.cs:290   C#
    Void UIRoot:Update ()+0x31 at C:\Users\Chuck\Desktop\_Unity\Projects\Game\Demo1\Assets\NGUI\Scripts\UI\UIRoot.cs:266   C#
Title: Re: Bug - UpdateAnchors called on object after OnDestroy
Post by: ArenMook on November 03, 2016, 08:01:12 AM
I can see that happening if the script is marked as ExecuteInEditMode, with it being called when you leave play mode and enter the edit mode again, but that's it.