Author Topic: Visibility Bug with Widgets When Enabling/Disabling?  (Read 14978 times)

kromenak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Visibility Bug with Widgets When Enabling/Disabling?
« on: January 30, 2014, 10:26:35 PM »
I have a sprite that appears and disappear in my UI from time to time.  To do this, I'm simply modifying the sprite's "enabled" property:

  1. player2Piece.enabled = enabled;
  2.  

However, when I enable the piece, it would occasionally not appear, though the game object and sprite component were both active/enabled.  I noticed that if I modify the sprites color, or if I suspend/resume the game, the sprite reappears.

So, digging into the UISprite/UIWidget/UIRect code, I found that only the UIRect is doing anything in OnEnable.  For some reason, if I comment out the OnInit line, my sprites appear consistently every time and behave as expected:

  1. // In UIRect code.
  2. protected void OnEnable()
  3. {
  4.     mAnchorsCached = false;
  5.     //if (mStarted) OnInit();
  6. }
  7.  

So, that seems to fix my issue...but I don't understand what that line does or why commenting it out causes the sprite to show as expected.  When toggling Sprite visibility, is it incorrect to use the "enabled" property of the component?  Is there a "right" way to do this that I'm not seeing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #1 on: January 31, 2014, 12:05:00 PM »
Which version of NGUI are you seeing this in? Enabling/disabling the widget should give consistent results. When you enable it, it tries to find the panel responsible for it by looking for it on the parent objects.

You can also set alpha to 0 to effectively disable it btw.

kromenak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #2 on: January 31, 2014, 01:28:52 PM »
Hey ArenMook, I'm using 3.0.9 f4.  To follow up, of course commenting out a random line in OnEnable causes issues elsewhere (particularly during editing, but still not great) ;).

So yeah - I switched to using the alpha instead and that seems to work fine.  I'm not sure if there's an issue with enabling/disabling or not, but basically I think this particular sprite also has an animation on it that adjusts its scale, so I think it is possible for the scale of the sprite to be 0,0,0 when it is first enabled, which might be causing issues with some calculations or something.

Anyway, just speculating there - I think my issue is resolved.  Thanks!

kromenak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #3 on: January 31, 2014, 03:15:35 PM »
As a final note, our studio updated from a 2.X release to the latest 3.0.9f4, and we've definitely gotten many instances where UI elements don't appear when they used to, or elements inexplicably don't appear until they are interacted with, or other odd visibility issues.

I have no idea why this is the case, but it is either some bug in the system, or we are using the UI elements incorrectly (which had worked with previous NGUI versions).

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #4 on: January 31, 2014, 06:42:08 PM »
this sounds very much like the issue i'm getting with items in my scrollview becoming invisible by themselves and becoming visible again as i scroll the content. And yeah, if its the same cause, that was introduced with one of the last 3-4 minor dot upgrades since it didn't happen for me before upgrading to the latest version from one of the last few dot updates and now happens a lot.

casperjeff

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 5
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #5 on: March 30, 2014, 08:52:39 AM »
Hate to jump on bandwagon - but similar thing here.
3.5.3
Mine is odd.
Essentially I have a scrollview with a grid that has sprites in it.
When the panel that has the content on it is first enabled - all is well - all sprites show properly in the scrollview...
Panel gets disabled (user goes 'back' to previous panel)...
when user goes back to this panel - all is well except the contents of that scrollview.  They are invisible (yet active)
weirdest thing is, if I click on the sprites IN THE EDITOR, they then show up in the game view!
I tried every combination (the sprites are in a grid) of reposition and such - no luck.

Really stumped here.


angelxv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #6 on: November 21, 2016, 11:57:45 PM »
Which version of NGUI are you seeing this in? Enabling/disabling the widget should give consistent results. When you enable it, it tries to find the panel responsible for it by looking for it on the parent objects.

You can also set alpha to 0 to effectively disable it btw.
Hi ArenMook, we also have this problem. we are using ngui 3.7.5 and because of soon to be released, we cannot upgrade ngui.... did you already resolved this problem and could you share the solution, then we can make a patch or something to solve in 3.7.5
thank you so much !

angelxv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #7 on: November 22, 2016, 05:15:16 AM »
to be more specific,
i use gameobject.SetActive() to set my obj visible/invisible. set invisible is fine. but after i re-set active to true, SOMETHINGS my obj cannot be visible on android device. reproduce probability is like 10%.
after searching in forum, i found that there was a NGUITools.SetActive() method, do i need to use this one instead of gameobject.setactive() ?
and i never let scale of my obj to 0.
i used leantween to animate my objs (only position).
if i attach child to my obj, and that child has animation on it(scale from 0.8 to 1), child is visible but parent (my obj) is not visible. my obj and its child are all UISprite.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Visibility Bug with Widgets When Enabling/Disabling?
« Reply #8 on: November 27, 2016, 04:05:49 PM »
Stick to one thread, please. As I mentioned in the other thread, there isn't much I can suggest. The fix in question was over a year ago.