Author Topic: UICenterOnChild fails in ScrollView with disabled children.  (Read 2070 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
I noticed that in a scrollView with children that are not active, the code below doesn't take that into account and returns the incorrect item.  I added the following line and it seems to work.  Perhaps you can see a better to fix this problem.

for (int i = 0, imax = trans.childCount; i < imax; ++i)
      {
         Transform t = trans.GetChild(i);
         if(!t.gameObject.activeSelf) continue; //Added this line.

         float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);

         if (sqrDist < min)
         {
            min = sqrDist;
            closest = t;
            index = i;
         }
      }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICenterOnChild fails in ScrollView with disabled children.
« Reply #1 on: June 07, 2014, 09:25:46 PM »
That seems fair, but I'd use "activeInHierarchy" instead.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: UICenterOnChild fails in ScrollView with disabled children.
« Reply #2 on: June 07, 2014, 11:19:40 PM »
This is a bug and not a feature request - please keep the two separate,  so whatever way is best to fix it is up your discretion.
« Last Edit: June 07, 2014, 11:46:48 PM by wallabie »

arun02139

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UICenterOnChild fails in ScrollView with disabled children.
« Reply #3 on: July 07, 2014, 01:19:38 AM »
I encountered the same issue, using wallabie's supplied solution without issue for the time being ~ thx wallabie!

Arun

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICenterOnChild fails in ScrollView with disabled children.
« Reply #4 on: July 07, 2014, 04:13:10 AM »
This change has been added a while back. If you had to modify your copy manually, then I suggest you update.