Author Topic: Problems cleaning up _RealTime  (Read 11868 times)

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Problems cleaning up _RealTime
« on: January 03, 2014, 05:07:39 PM »
Hi,

looks like I am using NGUI wrong some bugs were introduced in recent versions of NGUI. I am not sure, but it seems it started with v3.0.x. I until recently had 3.0.6 f5, just updated to 3.0.8 f4 and the problem remains. In 3.0.x < 3.0.6 this problem did not exist. I can't give you some conclusive theory on what happens, only a few hints.

Again, I am not 100% sure, but it seems the problem started when I started using UIStretch to stretch a screen fader GameObject (a fader covering the screen for a fade in/out effect). The effect works fine now and without errors in v3.0.x y 3.0.6, but on the console I now often get an error a la:

  1. UnassignedReferenceError: Variable mTrans of UIStretch is not assigned.

The variable UICamera of the UIStretch component is assigned (the Unity3D standard camera), the container variable is not. Is has worked fine until recently. I assume because of this, the console also says things like:

  1. Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)

(I don't use OnDestroy anywhere in my own code) and the infamous:

  1. !IsPlayingOrAllowExecuteInEditMode ()

As a result, the _RealTime object remains in the scene and accumulates on Play tests (i.e. five _RealTime objects in the scene after five Play tests). This (again, I assume) is responsible for errors I get when I deactivate a button OnClick that has a hover effect that changes the button color.

EDIT:
I get the IsPlayingOrAllowExecuteInEditMode error by simply extending the UIPanel component in the inspector of any GameObject, if the _RealTime object remains in the scene.

Interestingly, NGUI also sometimes keeps the fader GameObject activated after a Play test, where it is always deactivated by default. This does not always happen, but often enough so that a manual deactivation on my part becomes frustrating. The fader has a TweenAlpha component, which interestingly sometimes gets a OnFinished Event assigned automatically (which happens nowhere else in my scene, though I use a lot of TweenAlphas).

I am relatively sure NGUI is to blame for all this since it did work with v3.0.x < v.3.0.6.

EDIT:
Scratch that. It seems the UIButtonColor error:

  1. NullReferenceException: Object reference not set to an instance of an object
  2. UIButtonColor.OnPress (Boolean isPressed) (at Assets/NGUI/Scripts/Interaction/UIButtonColor.cs:152)
  3. UIButton.OnPress (Boolean isPressed) (at Assets/NGUI/Scripts/Interaction/UIButton.cs:90)
  4. UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
  5. UIKeyBinding:Update() (at Assets/NGUI/Scripts/Interaction/UIKeyBinding.cs:112)

is something else. I have buttons in my scene that are activated either via mouse click or via a key press (UIKeyBinding component). When I click the button, I get no errors. When I use the key press, I do get the above error. The way my buttons work is that they deactivate themselves (actually their parent, which holds all that kind of buttons) when being pressed to avoid multiple presses. This kind of setup has worked probably since I use NGUI, it started throwing errors just recently. This behavior happens no matter how many _RealTime objects there are in the scene.
« Last Edit: January 03, 2014, 05:34:07 PM by Bradamante3D »
#301224014, #301432336, #302399130

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems cleaning up _RealTime
« Reply #1 on: January 04, 2014, 09:32:11 AM »
Yup, that's a bug with UIKeyBinding. Change its Update function to the following:
  1. void Update ()
  2.         {
  3.                 if (keyCode == KeyCode.None || !IsModifierActive()) return;
  4.  
  5.                 if (action == Action.PressAndClick)
  6.                 {
  7.                         if (UICamera.inputHasFocus) return;
  8.  
  9.                         if (Input.GetKeyDown(keyCode))
  10.                         {
  11.                                 UICamera.currentTouch.current = gameObject;
  12.                                 UICamera.Notify(gameObject, "OnPress", true);
  13.                                 UICamera.currentTouch.current = null;
  14.                         }
  15.  
  16.                         if (Input.GetKeyUp(keyCode))
  17.                         {
  18.                                 UICamera.currentTouch.current = gameObject;
  19.                                 UICamera.Notify(gameObject, "OnPress", false);
  20.                                 UICamera.Notify(gameObject, "OnClick", null);
  21.                                 UICamera.currentTouch.current = null;
  22.                         }
  23.                 }
  24.                 else if (action == Action.Select)
  25.                 {
  26.                         if (Input.GetKeyUp(keyCode))
  27.                         {
  28.                                 if (mIsInput)
  29.                                 {
  30.                                         if (!mIgnoreUp && !UICamera.inputHasFocus)
  31.                                         {
  32.                                                 UICamera.selectedObject = gameObject;
  33.                                         }
  34.                                         mIgnoreUp = false;
  35.                                 }
  36.                                 else
  37.                                 {
  38.                                         UICamera.selectedObject = gameObject;
  39.                                 }
  40.                         }
  41.                 }
  42.         }

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: Problems cleaning up _RealTime
« Reply #2 on: January 06, 2014, 03:41:09 PM »
Hm, no, that get's me a

Quote
NullReferenceException: Object reference not set to an instance of an object
UIKeyBinding.Update () (at Assets/NGUI/Scripts/Interaction/UIKeyBinding.cs:107)
NullReferenceException: Object reference not set to an instance of an object
UIKeyBinding.Update () (at Assets/NGUI/Scripts/Interaction/UIKeyBinding.cs:114)

on button press. Line 107 and 114 are both

Quote
UICamera.currentTouch.current = gameObject;

Which means that the buttons do nothing right now.

At first I thought this happens because I deactivate the button GameObject on press (which has always worked until now), but removing this behavior does not improve things.
#301224014, #301432336, #302399130

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems cleaning up _RealTime
« Reply #3 on: January 06, 2014, 05:14:02 PM »
Hmm. Alright, try this:
  1. void Update ()
  2.         {
  3.                 if (keyCode == KeyCode.None || !IsModifierActive()) return;
  4.  
  5.                 if (action == Action.PressAndClick)
  6.                 {
  7.                         if (UICamera.inputHasFocus) return;
  8.  
  9.                         if (Input.GetKeyDown(keyCode))
  10.                         {
  11.                                 UICamera.currentTouch = UICamera.GetMouse(0);
  12.                                 UICamera.currentTouch.current = gameObject;
  13.                                 UICamera.Notify(gameObject, "OnPress", true);
  14.                                 UICamera.currentTouch.current = null;
  15.                         }
  16.  
  17.                         if (Input.GetKeyUp(keyCode))
  18.                         {
  19.                                 UICamera.currentTouch = UICamera.GetMouse(0);
  20.                                 UICamera.currentTouch.current = gameObject;
  21.                                 UICamera.Notify(gameObject, "OnPress", false);
  22.                                 UICamera.Notify(gameObject, "OnClick", null);
  23.                                 UICamera.currentTouch.current = null;
  24.                         }
  25.                 }
  26.                 else if (action == Action.Select)
  27.                 {
  28.                         if (Input.GetKeyUp(keyCode))
  29.                         {
  30.                                 if (mIsInput)
  31.                                 {
  32.                                         if (!mIgnoreUp && !UICamera.inputHasFocus)
  33.                                         {
  34.                                                 UICamera.selectedObject = gameObject;
  35.                                         }
  36.                                         mIgnoreUp = false;
  37.                                 }
  38.                                 else
  39.                                 {
  40.                                         UICamera.selectedObject = gameObject;
  41.                                 }
  42.                         }
  43.                 }
  44.         }

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: Problems cleaning up _RealTime
« Reply #4 on: January 09, 2014, 03:10:31 PM »
Yep, that works. Thanks.

The problems of _RealTime objects remaining in the scene and "Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)" or "!IsPlayingOrAllowExecuteInEditMode ()" being spammed in the console remain, though.
#301224014, #301432336, #302399130

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems cleaning up _RealTime
« Reply #5 on: January 09, 2014, 06:31:00 PM »
I see no reason for there to be more than one RealTime object. It's only created at run-time, and it's created with DontDestroyOnLoad, which doesn't keep it from play to edit time. Did you run into some other errors that has the side effect of keeping RealTime around?