Author Topic: MissingReferenceException: The object of type 'UIPanel' has been destroyed but y  (Read 20220 times)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
  1. MissingReferenceException: The object of type 'UIPanel' has been destroyed but you are still trying to access it.
  2. Your script should either check if it is null or you should not destroy the object.
  3. UnityEngine.Component.get_transform () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/UnityEngineComponent.cs:19)
  4. UIRect.get_cachedTransform () (at Assets/NGUI/Scripts/Internal/UIRect.cs:185)
  5. UIPanel.UpdateTransformMatrix () (at Assets/NGUI/Scripts/UI/UIPanel.cs:934)
  6. UIPanel.UpdateSelf () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1132)
  7. UIPanel.LateUpdate () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1093)

So, after upgrading from an old old version of NGUI, we now get this bug after running the game for a while in the editor. It triggers when we hit the play button to stop the game.

We've upgraded to the newest version of NGUI on Unity 4.3.4f1. Has anyone seen anything like it? Any solutions, hints anything?

After it's broken, then it fires that LogError every time you mess with just about anything - turn off a uipanel or back on, change a widget, resize the scene view.

It may be something we're doing as one of the hacks to get everything to run smoothly in the old version of NGUI, but that's basically limited to calling Refresh on UIPanels when they're activated, and we've tried to comment that out with the same result.


It's really hard to make a test case, because an empty project doesn't do this, which obviously leads me to think we're doing something wrong. :)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Pulling up the draw call tool after it's started to break, says "No NGUI Draw Calls present in the scene".

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Ok ok ok.. it's our fault. Something changed in the way UIPanels are handled internally and it made some of our dirty hacks break..

This is the culprit

  1.  
  2. public virtual void Show()
  3.         {
  4.                 gameObject.SetActive(true);
  5.                 if(!_anchorUpdated)
  6.                 {
  7.                         Component[] anchors = GetComponentsInChildren<UIAnchor>(true);
  8.                         foreach (UIAnchor anchor in anchors)
  9.                         {
  10.                                 _anchorUpdated = true;
  11.                                 anchor.SendMessage("Start", SendMessageOptions.DontRequireReceiver); //lol i brake ur stuff
  12.                                 anchor.SendMessage("Update", SendMessageOptions.DontRequireReceiver); //i halped
  13.                         }
  14.                 }
  15.  

They were there to make sure the anchors set things up immediately, because we were seeing a 1 frame delay when a screen was activated. If an anchor happened to be on a gameobject that also had a UIPanel, then SendMessage is sent to all the components, which means the Start and Update also ran in UIPanel - this meant that the UIPanel added itself to a global list twice; and OnDisable it only removed itself once. The second reference would then bluurrghh all over the codebase.


Let this be known, be careful with SendMessages. :)

We're gonna rip them all out and see if the frame delay is still there in the new version, then we'll solve that in some other way if it's still there.

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
Please excuse the dead-thread-resurrection, but I've been experiencing this issue with NGUI 3.6.3 and Unity 4.6.9f1 and I thought I'd post my solution for it in case anyone else has the same problem in the future and isn't making use of SendMessage.

In my case, the symptoms were exactly the same as Nicki, but the culprit was different.  I was making this call:
  1. NGUITools.ImmediatelyCreateDrawCalls(myPanel.gameObject);
while myPanel was inactive in the Hierarchy.  This made for bad times.

Hope it helps someone out there!