Author Topic: [NOT SOLVED] UIGrids - Smooth Tween causing Spring Position to never complete  (Read 3871 times)

Fliperamma

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 13
    • View Profile
    • Fliperamma | Game On!
Hi!

I'm developing a solitaire card game using UIGrids and Smooth Tween to change the cards from one UIGrid to another.
Sometimes, when I do the reparenting, some Cards have their Spring Position active for ever, with the position changing constantly but with very very small values (visually imperceptible)...

I've put a Log to track it down and found that it was not getting in to the "enabled = false;" line... (ex. 2.328306E-15 >= 1.392746E-10 == false):
  1. // line 96 of SpringPosition Class
  2. if (mThreshold == 0f) mThreshold = (target - mTrans.localPosition).sqrMagnitude * 0.00001f;
  3. mTrans.localPosition = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);
  4.  
  5. if (mThreshold >= (target - mTrans.localPosition).sqrMagnitude)
  6. {
  7.         mTrans.localPosition = target;
  8.         NotifyListeners();
  9.         enabled = false;
  10. }
  11.  


To solve it I'm checking if the local positions are different before applying the Spring Position in the UIGrid Class (If the positions are the same, there's no need to animate them)
> "&& Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f"

  1. // Line 369 of UIGrid.cs
  2. if (animateSmoothly && Application.isPlaying && Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f)
  3. {
  4.         SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
  5.         sp.updateScrollView = true;
  6.         sp.ignoreTimeScale = true;
  7. }
  8. else t.localPosition = pos;
  9.  

Solved my problem.. Any chance to have this (or something like that) in the next update?

Thanks
« Last Edit: July 15, 2015, 07:46:31 PM by Fliperamma »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Certanly. I'll add your change to the repository.

Fliperamma

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 13
    • View Profile
    • Fliperamma | Game On!
Yeap.. this post is OLD but this bug aged well :)

Can you please take a look / update this fix? I've just got the exact same problem again ... and fixed it again with the code that I've posted before ;)

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Hmm... wonder if I overwrote it at some point... I'll add it back in, thanks.