Author Topic: UIImageButton Colliders getting destroyed and replaced  (Read 3396 times)

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
UIImageButton Colliders getting destroyed and replaced
« on: August 12, 2012, 11:44:54 PM »
Hi,

I set up a panel of buttons and all seemed fine. I just went back to work on them and when I clicked through the button in the scene view (game not playing), my custom sphere colliders were destroyed and replaced with a new box collider. These two error messages where also printed:

  1. MissingReferenceException: The object of type 'SphereCollider' 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. UnityEditor.Editor.IsEnabled () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/Editor.cs:197)
  4. UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:814)
  5. UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:243)
  6. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
  7.  

  1. ArgumentException: Getting control 8's position in a group with only 8 controls when doing Repaint
  2. Aborting
  3. UnityEngine.GUILayoutGroup.GetNext () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:417)
  4. UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:217)
  5. UnityEngine.GUILayoutUtility.GetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:201)
  6. UnityEditor.InspectorWindow.CheckDragAndDrop (UnityEditor.Editor[] editors) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:368)
  7. UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:251)
  8. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
  9.  

Help!

Cheers,

- Rafe

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Colliders getting destroyed and replaced
« Reply #1 on: August 12, 2012, 11:46:31 PM »
NGUI doesn't destroy colliders like that. The question is, what did you do?

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Colliders getting destroyed and replaced
« Reply #2 on: August 13, 2012, 12:58:59 AM »
"what did you do"

Jiggled the knobs (reverted the prefab, updated nGUI, rebooted Unity) and it fixed itself. Seems to be stable. Moving on...


[EDIT] Its back. I'll have to tackle this with some fresh eyes tomorrow.
« Last Edit: August 13, 2012, 01:12:08 AM by Rafe »

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Colliders getting destroyed and replaced
« Reply #3 on: August 17, 2012, 11:00:48 PM »
Hi Aren,

I finally had a little time to debug this and it is being caused by this line in a custom version of the UIImage inspector:
  1. NGUITools.AddWidgetCollider(mButton.gameObject);

If I comment this out, my Sphere Collider stops being destroyed. Here is the problem code:
Line 275 of NGUITools.cs...
  1.                         if (box == null)
  2.                         {
  3.                                 if (col != null)
  4.                                 {
  5.                                         if (Application.isPlaying) GameObject.Destroy(col);
  6.                                         else GameObject.DestroyImmediate(col);
  7.                                 }
  8.                                 box = go.AddComponent<BoxCollider>();
  9.                         }
This says if there is a collider that isn't a box, destroy it. Do you recall why?

Cheers,

- Rafe
« Last Edit: August 18, 2012, 12:45:15 AM by Rafe »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Colliders getting destroyed and replaced
« Reply #4 on: August 18, 2012, 03:25:38 AM »
Assuming you were talking about UIImageButtonInspector, change that line to:
  1. if (mButton.collider == null || (mButton.collider is BoxCollider)) NGUITools.AddWidgetCollider(mButton.gameObject);