So I would like to preface this by saying that I have only tested this with Buttons, Text, and Images. I am also using the “Legacy” Animations.
I have a Text UI element in a Canvas and it shows up perfectly. Then I go in and add an Animation that is 2.0 seconds long, and simply changes the Text Color Alpha from 0 → 1 over 2 seconds. When I play the game in the Editor, looking into the Inspector for the Text element shows that the Color Alpha animations properly (Going from 0 → 1), but in the Editor view, the text is entirely invisible.
Doing anything to the Text element - Moving it, changing the Alpha manually, changing the font size, text, etc. - instantly shows the text as it should be, with an Alpha value of 1.
I am sure this is not intended, and just some weird graphical bug. Hope it can get fixed in the next Beta update!
Mainly because that’s what I’ve always used, and I find the newer system slightly confusing. And until now I’ve never had a problem with the Legacy system for simple things like this.
As for the “Why are you using it for this?” thing, the legacy system is lighter on the system if you don’t use fancy features like blending.
My use case is Ui sprites. I created a set of animations, which combine Alpha fade out with translations and sometimes rotation. I can use the same animations on all sprites in the game and trigger them by code. Having one animator per object would be overkill…
Anyway, if anyone has a workaround for this, that would be great.
So would someone be able to write a script that could set this flag manually, or is the proper solution to just give up on our precious Legacy and move on?
It seems like a fairly easy feature for Unity to have Legacy animations set this flag. I truly hope Unity isn’t planning on ditching the Legacy system in future releases. Not only is it often more convenient for simpler effects (nearly anything non-character), but it’s also already been learned and adopted by the majority of your customers. #FeatureKeep
If your class inherits from UIBehaviour (the base UI class) you get a callback when any animation is run. You can achieve the same results above in a cleaner way doing this.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Update : UIBehaviour
{
private Image m_image;
public Image image
{
get
{
if(m_image == null)
{
m_image = GetComponent<Image>();
}
return m_image;
}
}
protected override void OnDidApplyAnimationProperties()
{
image.SetAllDirty();
}
}
@BMayne Thank you for that little gem. Looks like I need to start digging up dirt on this newfound UIBehaviour.
It would still be nice for Unity to update the Legacy system.
Oh super lame. I could have swore that is how we got around the issue in one case. Here is another solution that I know will work. Instead of just calling play you start a coroutine.
Wow, just got that issue too…“Playing a single Animation Clip with no blending can make Mecanim slower than the legacy animation system. The old system is very direct, sampling the curve and directly writing into the transform. Mecanim has temporary buffers it uses for blending, and there is additional copying of the sampled curve and other data. The Mecanim layout is optimized for animation blending and more complex setups.”…and we can’t use legacy to animate the color of a text…ok…seems totally logic ???
I know this issue is somewhat old, but I did notice that if you call “image.SetVerticesDirty” every frame while the animation is running, the alpha works as expected. But in Unity 5.2, at least, doing this allocates some amount of memory each time you call SetVerticesDirty, which isn’t ideal.
A decent workaround seems to be that if you attach a CanvasGroup component and animate the alpha value on that instead of the image.Color.alpha value directly, alpha animations do work and the profiler shows no memory allocations.
We just had the issue. That would be great to fix it.
CanvasGroup workaround is good but you need to redo your animation, that’s a lot of wasted time.
We use 5.1 so SetAllDirty will do the job.
We REALLY need that the legacy animation would be called “simple animation” instead, and that it takes into account all the new features coming along.
I’m mainly thinking about sprite animation and alpha animation.
It’s reaaaally frustrating to work on simple games because of that.
We’re not going to add new features to the legacy system. We’d rather spend the time working on improving Mecanim usability instead so that you no longer have any need to use the Legacy system.
Yep, performance improvements are always possible. I think some good progress has already been made on this front in 5.4.
Also, little-known fact: the Playables API, introduced in 5.2, makes it possible to pretty much build your own version of the Animation component, or something even simpler (e.g. “just play this one animation clip on a loop kthx”)