Author Topic: Progress bar staying visible even when I leave the scene.  (Read 4143 times)

P15Studios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Progress bar staying visible even when I leave the scene.
« on: October 01, 2013, 12:12:27 AM »
I have a progress bar that progresses on an action. When the action is done, I setActive(false) the Anchor that it's in. Then, the progress bar won't go away. The only way to get it to go away is to restart Unity. I set the anchor to inactive and nothing helps. Is this common? Am I'm doing something silly?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Progress bar staying visible even when I leave the scene.
« Reply #1 on: October 01, 2013, 07:19:31 PM »
No, it's not normal. You need to provide more details to go on. Version of NGUI, version of Unity, what you use to disable it (Unity's functionality or NGUITools?), whether you disable the game object or just the UIAnchor component, etc.

P15Studios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Progress bar staying visible even when I leave the scene.
« Reply #2 on: October 02, 2013, 09:30:15 AM »
4.2.1f4 Pro Unity
NGUI 2.7

I get access to my anchor and I disable it. I am doing this for a bunch of other things in NGUI ann never have a problem, this is the first I've seen it.

On Start:
  this.pausedAnchor = GameObject.Find("PausedAnchor");

OnPauseGame:
  this.pausedAnchor.SetActive(true);

OnResumeGame:
  this.pausedAnchor.SetActive(false);

The anchor is set up like this:
  Anchor
    Panel
      Sprite with animation from right to left
      Sprite with animation from left to right
      Button
      Button
      Button
      ProgressBar

Thanks for the help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Progress bar staying visible even when I leave the scene.
« Reply #3 on: October 02, 2013, 05:18:56 PM »
SetActive(true) in Unity enables children before enabling parents, which is a problem. You need to use NGUITools.SetActive instead.

P15Studios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Progress bar staying visible even when I leave the scene.
« Reply #4 on: October 03, 2013, 10:25:28 AM »
Followed your advice, which totally makes sense. However, the same problem still happens. I even tried using the SetActiveChildren, Self and just SetActive.

When a character collides with a cube, I want to pop up the progress bar and have it at 0.0. When the character presses "y". the slider should go from 0.0 - 1.0. If the character stops colliding, the slider should fall back to 0.0 and disappear. If the user lets go of Y before the slider hits 1.0, I want to reset it to 0.0 and then disappear. If the slider hit's 1.0. I want to reset it to 0.0 and make it disappear.

Stack trace below.

Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object:DestroyImmediate(Object)
NGUITools:DestroyImmediate(Object) (at Assets/Plugins/NGUI/Internal/NGUITools.cs:514)
UIPanel:OnDisable() (at Assets/Plugins/NGUI/UI/UIPanel.cs:705)
UnityEngine.GameObject:SetActive(Boolean)
NGUITools:SetActiveSelf(GameObject, Boolean) (at Assets/Plugins/NGUI/Internal/NGUITools.cs:669)
AmountStolen:OnTriggerStay(Collider) (at Assets/Scripts/InGameHUD/Amount.js:53)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Progress bar staying visible even when I leave the scene.
« Reply #5 on: October 04, 2013, 02:23:28 AM »
Yeah, you can't disable UI elements from a physics callback. You need to delay the action by starting a coroutine.