Author Topic: In Start(), how to set my scrollview's position to SpringPanel's target position?  (Read 8178 times)

alexh0101

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 30
    • View Profile
I have a scroll view set at position x = -600.
When my scroll view becomes active at runtime, a script called SpringPanel appears and its target is x=-554.0437.

The value 554.0437 seems to be the exact center of the Scrollview's container so that's what I want.

So the items in my Scroll view, shift slightly from -600 to -554.0437.

Why is this happening? How can I make sure the scrollview is at 554.0437 before it becomes visible?
I tried to set the scrollview's position to = theScrollView.GetComponent<SpringPanel>().target.x but I get an error.

Thanks a lot

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Select your scroll view, right click the script and choose "Reset Clipping Position". This will move the scroll view's content to where it will be when you hit Play. Once you do that, hitting Play won't move the scroll view's content anymore.

alexh0101

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 30
    • View Profile
Hi there, thanks for your response.

It seems that the problem comes from UICenterOnChild, which is attached to the grid.
The items within that grid are instantiated in Start().

I tried to right-click on UICenterOnChild and "Execute", but it didn't change anything.
Is there a way of executing the UICenterOnChild script right after the instantiation of the items?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Quote
Is there a way of executing the UICenterOnChild script right after the instantiation of the items?
You can call its Recenter() function after instantiating your items, or you can adjust your script's execution order so that it runs before UICenterOnChild. UICenterOnChild does its reposition in Start().