Author Topic: Help with uiPanel  (Read 9753 times)

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Help with uiPanel
« on: August 20, 2013, 06:20:12 PM »
Hi. I've been using Ngui in my game pretty heavy and it's been working great.

The last panel I created is having some weird issues. When I first load the scene the panel is on I can enable and disable it all day long and it works great. If I load a different scene and come back to the previous one and try to invoke just that one panel it errors out telling me in trying to access an object that's been destroyed. This is the only panel out of many that have this issue. I'm not using any don't destroy calls in my scene.


Anyone have any ideas ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with uiPanel
« Reply #1 on: August 21, 2013, 10:25:53 AM »
Can't say I've seen this before. What version of Unity & NGUI?

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #2 on: August 21, 2013, 12:42:47 PM »
I'm running the latest Ngui and free version of unity. One rev back from 4.2. I'm not at home at the moment. I'll look when I get there. One thing to note is I am disabling a button on this panel through code where my other forms I have just went in and disabled the box collider.

That's the only thing I can thing if that's different.

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #3 on: August 21, 2013, 05:42:01 PM »
OK running NGUI 2.6.4 and just updated to Unity 4.2.0f4. I tried removing the code to not disable the button and it still does it. when I click on the error it takes me to NGUITools under the SetActive.

The exact error is: Missingreferenceexception: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if its null or should not destroy the object.

I have even tried reimporting NGUI. One thing I did discover after reloading unity is I did have to change the z transform on my panels to get the text to show again on the labels. it was working fine before.

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #4 on: August 21, 2013, 10:44:55 PM »
Still working on it. Here some things I have tried

Created a brand new panel and moved all the widgets to it. Didn't help

I've tried to comment all the code after the call to setActive on the gameobject. Didn't help.

Perhaps a better description of the setup may help.

The panel game object is connected to a public variable in the inspector.
I do this with all my panels. In the start function I set it active false to hide it.
A function from another script calls a function in the main script which enabled the panel game object and then sets things like labels etc on the widgets themselves. I'm using this method throughout and it works flawlessly.

I'm beginning to wonder if its a problem with one if the child widgets. One bug I've seen is when doing a command d to duplicate a button object. After you do this a couple times the third button object starts getting a uiPanel script attached to it as the last script. I'm not sure why this does this but I've seen it before and had to remove it.

Another thing that's kind of annoying and I'm not sure if its just a unity glitch is when duplicating the objects the scale for the duplicated object gets set to 1.008 for x y z
Not sure why but this also is kind of annoying.

Any other ideas ? Any debug scripts to could send me to try and troubleshoot??

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with uiPanel
« Reply #5 on: August 22, 2013, 10:36:39 AM »
As I recall, Unity had long had a bug where it enabled children before parents when you did SetActiveRecursively. Maybe it's related to that?

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #6 on: August 22, 2013, 10:40:51 AM »
I was not using SetActuveRecursivley

I was just using setActive.

Should I use that on my panels instead ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with uiPanel
« Reply #7 on: August 22, 2013, 10:52:30 AM »
SetActive goes through the same code.

You basically have to modify the script execution order and ensure that your child script is executed after your parent script.

TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #8 on: August 22, 2013, 11:27:54 AM »
In my case the enable and disable happen from the main same script. The other script is a small script that attaches to a gameobject to animate and tell it to call the Open Function in the main script.

I noticed that since installing NDATA I do have some script order UIPanel is set to 100. IS that normal for an NGUI Install?

I have attached an image of my execution order. Does this look normal for NGUI Install?


TommyT31

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Help with uiPanel
« Reply #9 on: August 26, 2013, 09:09:53 AM »
SOLVED!!

Ok so I figured this out. By adding a button onto another UIPanel in my scene to just open and close the panel it was able to work. What didn't was calling the open from the other script. I was using C# messenger to call the scripts function. There must have been a problem with script order as you said even though I tried rearranging both the offending scripts and the c# messenger script within the execution order.

Thanks for the suggestions you got me pointed in the right direction. Hopefully I can start growing back some of this hair i've been pulling out.

BTW: Did you look into the object duplication issue I mentioned? Its where you add say a button widget to a panel, then highlight the root object and start hitting command d to duplicate, after about the 3rd button widget a UIPanel starts getting tacked onto each subsequent button. Not sure why even though they are all off a root UIPanel. Also for some reason the objects that get duplicated are always at a scale of 1.0008 1.0008 and 1.0008 , kind of annoying not sure if there is a way to tweak that so that are always the same as the object being duplicated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with uiPanel
« Reply #10 on: August 27, 2013, 02:55:33 AM »
The scale is the side-effect of Unity's lossy scaling combination. The panel... related to the image button / UITexture (?) in 2.6.4.