Author Topic: Prefab sprites disappearing in 3.0.8 f2  (Read 11331 times)

juharkonen

  • Guest
Prefab sprites disappearing in 3.0.8 f2
« on: December 30, 2013, 10:43:33 AM »
I have a scroll list where I instantiate the list items (button+sprite) from a prefab. After I updated to 3.0.8 2f these items are invisible. I think the previous working version was 3.0.7 f2 (updated 27th December). The bounding boxes and colliders are there and the button can be clicked normally, but the background sprite and label are invisible. Also static buttons work as before, the issue only occurs with the dynamically instantiated buttons on scroll views.

I've tried to narrow down the problem with little success. The best I've been able to find out this far is that if I take one of the list items during runtime in Unity Editor, move it outside the clipping panel and switch sprite type from sliced to simple (and optionally back to sliced), the sprite becomes visible. If I move it back to the clipping panel it remains visible. However if I then switch the sprite type it becomes invisible again.

The Latest Version thread header names 3.0.8 f2 as the latest version but the last change list is for 3.0.8. Is there any specific changes in 3.0.8 f2 that could have caused this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #1 on: December 30, 2013, 12:56:42 PM »
3.0.8 has a bug related to how widgets get added to the panels. 3.0.8 f2 fixes this. Which version do you actually have? You can check the readme file, it has the version # inside.

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #2 on: December 30, 2013, 08:50:07 PM »
I have 3.0.8 f2, and have a similar issue.

I create a scroll panel with a grid in it, and then dynamically add buttons to the grid.  In 3.0.8f1, the buttons were laid out correctly, in 3.0.8f2, all of the buttons sit on to of each other.

Something else that is strange, if I delete the whole UI tree (think window-like), and then re-add it, it works correctly.  if I save the scene, and load a different scene and come back, it still works.  If I quit unity, and restart it sometimes it works, sometimes it doesn't...  I'll continue to try to narrow it down further; once I do, I'll provide more details.

juharkonen

  • Guest
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #3 on: December 31, 2013, 03:16:53 AM »
Checked the readme and the version is 3.0.8 f2.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #4 on: December 31, 2013, 04:27:20 AM »
@John: The UIGrid script must be enabled for its Reposition() function to work. I did the following:

1. Created a sprite for the scroll view's background with a collider on it.
2. Added a scroll view, resizing it to the sprite's dimensions.
3. Added UIDragScrollView to the sprite from #1, made it point to the scroll view.
4. Created a simple prefab out of a game object with a child sprite and label, with UIDragScrollview and a box collider on it.
5. Added a child object under the scroll view, put UIGrid on it.
6. Created a test script referencing the prefab from step #4, on Start() it instantiates 10 objects via NGUITools.AddChild, then calls UIGrid's Reposition() function.
7. Attached the script from #6 to the same game object as UIGrid.

Objects get instantiated correctly and show up as expected. If the UIGrid is disabled, all items show up on top of each other (as expected).

@juha: I can use more details on how to reproduce the issue. Note the steps above. What are you doing differently?

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #5 on: December 31, 2013, 01:57:53 PM »
Question about #6, do you call reposition after you have added all of the items, or after each item itself (ie, 10 calls or 1 call)?

FWIW, I've not had the problem again since the other day - so I suspect it must be some sort of a timing issue (race condition).

Since the f3 update, it looks like the scrollbar position gets reset to the middle, I want it at the top.  I added code to get the scrollbar, and set its value to 0, but the value is already 0 at that point.  I am adding all of the controls in the start() method of a script attached to the main component of the UI hierarchy.  so the current logic is something like this:

Get the Grid
Get the UIGrid component
Add the buttons to the grid
Call reposition on the UIGrid component

Get the scrollbar
Get the UIScrollbar
set the scrollbar.value to 0

still, when the window opens, the scroll bar is centered.

is there a simpler way to make sure the top item in the list is visible when the UI "window" is displayed?
« Last Edit: December 31, 2013, 02:41:10 PM by John.Bergman »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #6 on: December 31, 2013, 03:39:44 PM »
Scroll bar will be centered if your scroll view's content is centered. Scroll bar simply visualizes the content's position until you move it. Move your content in your scroll view if you want it to be different.

juharkonen

  • Guest
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #7 on: January 01, 2014, 07:45:25 AM »
Got my issue figured out - the clipped panel used the same depth value as another panel up in the UI hierarchy and window background sprites were rendered on top of the list items. Incrementing the clipped panel depth resolved the issue.

Edit: it looks like the sprite depth values are no longer used for ordering sprites rendered by different panels. I didn't check the last working version of my project before the recent NGUI version updates to confirm this though.
« Last Edit: January 01, 2014, 08:15:44 AM by juharkonen »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #8 on: January 01, 2014, 07:31:11 PM »
That's correct. Sprites with the same depth are no longer mixed if they are in different panels.

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #9 on: January 02, 2014, 01:59:03 AM »
Scroll bar will be centered if your scroll view's content is centered. Scroll bar simply visualizes the content's position until you move it. Move your content in your scroll view if you want it to be different.

Not sure how I would do that since I am dynamically adding all the children to the grid....  Any pointers?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #10 on: January 02, 2014, 11:22:48 AM »
Move the grid's game object around. Add a couple of items at edit time to see how they will be positioned. Position the grid object, delete the items.

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Prefab sprites disappearing in 3.0.8 f2
« Reply #11 on: January 02, 2014, 12:29:44 PM »
Thanks.  Moving the Grid's game object fixed it, although IMHO, that behavior is not intuitive; I had originally been looking for some center on parent type of setting which is what I would have expected based on what I was seeing.

The functionality I basically implemented was a "listbox", that might be worthy of adding a control/prefab to your controls collection...