Hello.  I have attempted to implement Flash SetEase for DOColor for a couple of different situations, but in both cases, problems occur if it is started again when it is already in progress.

In my first case, I attempted to make an enemy flash white briefly upon being hit, by changing the material renderer color.  If it is hit twice in a row, the object will permanently stay white and never go back to the original color.

In the second case, I tried to make an outline in the UI blink for a few moments when health is restored.  However if it happens while the flashing is already activated, the flash rate will appear to be on white twice as much, which is expected.  However after the flashing stops, the next time the flashing is activated it will retain the undesired double white period, and the problem can be repeated until it will only appear as solid white with no flashing.

The code used is below, it is fairly straightforward.

Code: [Select]
Case 1:
rend.material.DOColor(Color.white, 0.02f).SetEase(Ease.InFlash, 4, 0);

Case 2:
Color whiteopaque = new Color32(255,255,255,255);
Text.GetComponent<Outline>().DOColor(whiteopaque, 1.6f).SetEase(Ease.InFlash, 28, 0);


I thought of putting a bool there to prevent the flash from reactivating, that would reset after OnComplete, but I want a new activation to reset the flashing duration instead, so to do that I had to use a coroutine instead of the SetEase to get the functionality I want.

However, I was wondering if you have any suggestions or if DoTween has any built in functionality to prevent the double flashing / stuck white problem, or a way of adding to the timer that I am not aware of.  I would like to use DoTween if it is possible!  Thank you very much for any advice!

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Hi!

The issue you're having is simply due to the fact that, when a tween starts, the current value of its target is considered the starting point. So if your Color was almost white (because of the Flash) when you started another tween, it will go from that almost-white to white.

You should store the tween, and simply restart it when your target is hit again, like this:
Code: [Select]
// Create the flashing tween (store it in a class variable)
// Note that I use SetAutoKill(false) to prevent the tween from being killed after completion
// (this way you can reuse it)
myTween = Text.GetComponent<Outline>().DOColor(whiteopaque, 1.6f).SetEase(Ease.InFlash, 28, 0).SetAutoKill(false);
// ...
// Restart the flashing tween
myTween.Restart();

Cheers,
Daniele

Perfect solution, the restart does exactly what I needed it to so I can repeat the tween when another hit or activation occurs.  Here is the code I used after the fix:

Code: [Select]
if (isFlashing == false)
{
isFlashing = true;
myTween = rend.material.DOColor(Color.white, 0.2f).SetEase(Ease.InFlash, 2, 0).SetAutoKill(false).OnComplete(ResetFlash);
}

if (isFlashing == true)
{
myTween.Restart();
}

Thanks so much for the help! DOTween is the best!

BTW why is the forum hit with so much spam?  :(

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Great, and thanks for the thanks :)

And damn, I don't know what's happening to the forum :( Also, for some reason I don't get notifications of spam topics, so I don't see them until I come check for them on purpose :( Gonna clean it a little now, but I did it already a couple days ago and it didn't suffice. Siiigh.

I have another question related to this, as I am expanding on where I can use the Flash Ease functionality.  Is there any way to define or force the start value of the ease/tween?  In my case I'm dealing with color, so my problem is that if I do want to have simultaneous flashes I don't want the Flash Ease to get its starting color from the wrong state.  I already have my desired start values stored as a color list when the game object is generated, but I need a way to tell DOTween to always go back to my stored color rather than the color it sees when it starts.  Though I'm guessing it may be possible with generic ways, I'm not experienced enough with lambdas or the generic coding way to figure out the syntax.

Would you have any suggestions on how I could use a predefined starting value for the Flash Ease?  Thank you!

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Ahoy!

There is no way to tell DOTween what starting value to start from, since it always takes it's target current one. That said, just set your color to the given value before creating the tween and you're done ;)