Tween caching issue
« on: July 21, 2015, 02:04:58 PM »
Hello,

I am using DoTweenPro and I am trying to implement a floating score feature that shows above the enemies whenever you hit them. I have added a tweenComponent to a FloatingScore gameObject that moves the score text relative to the position of the object it is shown above. However if I add the FloatingScore gameObject to an object pool, for some reason the DoTween system caches the start position of the first object to which it is shown above. Whenever I get an already used FloatingScore object from the pool, although I change its transform, the tween is moved relative to the previous position of the object. I have gone through the DoTween documentation and read that the DoTweenPro system is actually caching the tweens for optimization purposes and I am pretty sure that this is causing my issue. Is there a way to disable the cache or to reset the tween values?

I have workaround the issue by removing the DOTweenAnimation component from the game object and simply using DOMove on the transform once I get the game object from the pool, but I am not sure that this is the best way to implement.

obj.GetComponent<RectTransform> ().transform.DOMove (alteredPosition, 0.5f).OnComplete(() => obj.SetActive(false));

Thanks

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Tween caching issue
« Reply #1 on: August 04, 2015, 05:54:03 PM »
Hi, and sorry for the late reply (the notification system broke),


To use visual tweens with a polling system, add a manager to your gameObject (by using the "Add Manager" button on one of the DOTweenAnimations attached to it), and select the "Pooling System" preset. That will un-cache the starting position each time your gameObject comes back from a disabled state.

Re: Tween caching issue
« Reply #2 on: August 11, 2015, 03:50:28 PM »
Hi, and sorry for the late reply (the notification system broke),


To use visual tweens with a polling system, add a manager to your gameObject (by using the "Add Manager" button on one of the DOTweenAnimations attached to it), and select the "Pooling System" preset. That will un-cache the starting position each time your gameObject comes back from a disabled state.

Thank you very much, Daniele. That did the trick.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Tween caching issue
« Reply #3 on: August 11, 2015, 09:39:33 PM »
Great :)

Re: Tween caching issue
« Reply #4 on: October 09, 2015, 07:42:45 PM »
Hi Daniele,

Is it possible to do this directly through scripting? I have a similar problem where a color & scale sequence is seemingly holding onto a cached starting value, instead of tweeting from the current value.

Here's more specific information of my problem (hopefully understandable!)
I have three sequences on two button objects:

Focus
Defocus
Normal

OnKeyDown.KeyCode.Q = Button1 plays its Focus sequence and Button2 plays it's Defocus sequence.
OnKeyDown.KeyCode.E = The opposite happens.
OnKeyUp.KeycodeQ || E =  All sequences are paused. Both buttons play their Normal sequence.

The problem: I want the normal sequence to tween from the current value. It seems that the Normal sequence holds onto it's original starting value the first time it is played.

Am I missing something? Can you help?

Thanks!

Ben

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Tween caching issue
« Reply #5 on: October 09, 2015, 07:59:10 PM »
Hi Ben,

Every tween/Sequence always stores its starting value the first time it's played, and it will be fixed forever and ever from that moment on.

But what are you trying to do exactly? Maybe using the same Sequence and playing it backwards and forwards would achieve the same?

Cheers

Re: Tween caching issue
« Reply #6 on: October 09, 2015, 08:14:57 PM »
Ah I see, I think maybe I am approaching this the wrong way then. I'm not very tween-experienced, so forgive me if these are simple questions!

Question 1:
Can you explain how best to setup things in this situation?

Taking a simplified example: I have a red cube.

If I hold down the "Q" key on my keyboard, the cube should color tween from Red to Blue
If I release the "Q" key, the cube should color tween from it's current color back to Red.

If I hold down the "E" key, the cube should color tween from Red to Green.
If I release the "E" key, the cube should color tween from it's current color back to Red.

Do I have to set the starting value for each tween, based on the cube's current color?

Question 2: (semi-related)


Is the problem I'm having due to the fact that I am storing references to Tweens and Sequences, instead of just instantiating a new tween each time?

I'm trying to work out the best/most optimised approached to using DoTween. In general I am using the same tweens on the same UI objects repeatedly in my project, so I thought it best to store a reference to each tween and set AutoKill to false until the game objects are destroyed. Is this the correct approach to using DoTween?

Thanks for you help!

Ben


*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Tween caching issue
« Reply #7 on: October 11, 2015, 02:59:38 AM »
The best way is indeed to store the tweens and reuse them, when possible. But indeed sometimes it's not, like in your case. A tween is fixed once started, so if you want to animate from a different start-value/color to a different end-value/color, I would definitely suggest to create a new tween each time instead. Tweens are very lightweight anyway, so if you can't always store them it's not a problem :)