Author Topic: UI Scroll View items start at (0, -6428, 10)  (Read 4351 times)

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
UI Scroll View items start at (0, -6428, 10)
« on: February 16, 2014, 06:58:37 PM »
I've created a scroll view by doing the following:

1. NGUI > Create Scroll View
2. Named scroll view MyScrollView
3. On a button press, I instantiate a new ScrollItem prefab, and set it's transform.parent to MyScrollView.transform.

When I do this, my newly instantiated item is positioned at (0, -6428, 10), as are all subsequently instantiated items. Their prefabs have a position of (0, 0, 0), and even adding them to a UIGrid child of MyScrollView doesn't have any different effect (they just stack on top of each other at 0, -6428, 10).

In your instructional video here: http://www.youtube.com/watch?v=OiA4o8KqBFI, you add scripts like UIDragPanelContents, but those don't seem to exist any more. I have added UIDragScroll to my items, and the scrolling does work if I manually drag the items within the panel's viewable area, and they snap to the top of the list if I drag above it. I just can't seem to get them to start out that way (at the top of the list, as you would expect).

What might I be doing wrong?

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI Scroll View items start at (0, -6428, 10)
« Reply #1 on: February 17, 2014, 11:04:36 AM »
You need to use NGUITools.AddChild(parent, prefab) to instantiate items. Look inside that function to find out why.

Don't just instantiate things in the middle of nowhere and then reparent them like you're doing. Your object layer and transform scale are likely way off as well.

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UI Scroll View items start at (0, -6428, 10)
« Reply #2 on: February 17, 2014, 11:49:10 AM »
Thank you for your response.

That helped a bit. The grid now starts at (0, 0, 0), as expected. However, the grid script itself is deactivated, and I can't activate it.

This is what I have:

MyScrollView (UIPanel, UIScrollView, UIDragScrollView, BoxCollider, RigidBody)
-- MyGrid (UIGrid)
  -- List of instantiated prefabs (UIWidget, UIDragScrollView)

All of the instantiated prefabs just stack on top of each other, because the UIGrid is deactivated. How can I get this UIGrid functioning?

Thanks again!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI Scroll View items start at (0, -6428, 10)
« Reply #3 on: February 17, 2014, 11:53:47 AM »
GetComponent<UIGrid>().Reposition();

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UI Scroll View items start at (0, -6428, 10)
« Reply #4 on: February 17, 2014, 12:27:01 PM »
Perfect. Thanks!