Author Topic: NGUI BUG (+FIX): UIGrid + smooth animate  (Read 6541 times)

soulburner

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 22
    • View Profile
NGUI BUG (+FIX): UIGrid + smooth animate
« on: February 21, 2017, 07:10:31 AM »
I've been experiensing some random bugs with UIGrid with "smooth animate" enabled when some items overlapped.

A digging through the NGUI code lead me to the reason.

So, I've found that there was a situation where the Spring component was disabled, but its target was very far from the real point of the object.

Then, I've discovered that somebody changed the spring's target after the initial setup.

And here's the code:

UIGrid.cs:414
  1.                                 SpringPosition sp = t.GetComponent<SpringPosition>();
  2.  
  3.  
  4.                                 if (sp != null)
  5.                                 {
  6.                                         sp.target.x -= fx;
  7.                                         sp.target.y -= fy;
  8.                                 }
  9.  

This piece of code changed the spring's target, but didn't force Spring to be enabled. So, if the Spring component was disabled by this time, nobody enabled it and it didn't move the item to the target point.

So, I needed to add something like:
  1.                                         sp.target.x -= fx;
  2.                                         sp.target.y -= fy;
  3.                                         sp.UpdateTarget();
  4.  

and also add a method to SpringPosition.cs:

  1.         public void UpdateTarget()
  2.         {
  3.                 mThreshold = 0f;
  4.                 enabled = true;
  5.         }
  6.  

Also, seems that UITable.cs : 277 will cause the same issue.
Programmer at LazyBearGames.com
Making Punch Club and Graveyard Keeper

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI BUG (+FIX): UIGrid + smooth animate
« Reply #1 on: February 21, 2017, 12:29:16 PM »
Thanks, I'll make similar changes on my end and see if they cause any adverse effects.