Author Topic: Bug - UpdateAnchors called on object after OnDestroy  (Read 2197 times)

Dune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Bug - UpdateAnchors called on object after OnDestroy
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug - UpdateAnchors called on object after OnDestroy
« Reply #1 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. ...

Dune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Bug - UpdateAnchors called on object after OnDestroy
« Reply #2 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#

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug - UpdateAnchors called on object after OnDestroy
« Reply #3 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.