Jump to content

Hiding an animation when it stops (?)


Recommended Posts

I'm trying to work on supporting a blinkenlights looping animation in RasterPropMonitor. Sumghai's post on the FusTek Station Parts Dev thread illustrates the idea.

What I have currently is:

Before I play the animation, the lamps are all off (the animation is not visible).

When I start playing the animation, the lamps blink (per the animation).

When I stop playing the animation, the lamps freeze (some on, some off).

What I want is to make the lamps (the animation) not visible when the animation stops.

Is there a way in Unity to make the lamp animation not visible again, like before it was played?

I know sumghai can change the animation so frame 0 has all the lamps off, but that introduces a periodic flicker on the power indicator lamps, which is not ideal, so I would like to see if there's another way to change the animation state. My Unity-specific expertise is minimal, and I'm not entirely sure what I specifically need to look for.

-MOARdV

Link to comment
Share on other sites

Why not use two animation clips? One would be a single-shot, single-frame clip of the lamps being off, the other your looping, blinking animation. Instead of stopping the animation, "play" the stop clip.

You can, of course, simply disable the lamps in code when you stop the animation

Link to comment
Share on other sites

Like this?


Nameofyouranimationstate.normalizedTime = 0;
"=".normalizedSpeed = 0;

This will stop the animation and set it to the start time. If the light is off at this time in the animation then you should be good. You can also use blend to get a smoother transition. Or you can reverse the animation with normalizedSpeed = -1; and clamp it when it reaches 0.

Hopefully i didnt misunderstand what youre trying to do here. If so then just ignore this:-P

Link to comment
Share on other sites

Like this?


Nameofyouranimationstate.normalizedTime = 0;
"=".normalizedSpeed = 0;

This will stop the animation and set it to the start time. If the light is off at this time in the animation then you should be good. You can also use blend to get a smoother transition. Or you can reverse the animation with normalizedSpeed = -1; and clamp it when it reaches 0.

Hopefully i didnt misunderstand what youre trying to do here. If so then just ignore this:-P

Except that there is no frame in the animation where the lights are off. They are on for every frame, so when I set normalizedTime and normalizedSpeed to 0 (which I already do), the animation is visible, because the lights are on in every frame of the animation. They are not visible before I play the animation (I don't know why), but they are always on once I start the animation (because all frames have lights on).

Link to comment
Share on other sites

As MOARdV mentioned previously, I can easily modify my animation to have the first frame as the "off" state - however, playback of the animation loop would include that first "off state" frame, resulting in the aforementioned (and undesired) flicker in the POWER LED indicators.

Is there a way to tell the loop playback to skip certain frames in an animation? According to Unity docs, it appears that Unity works with time indexes rather than frames, which compounds the problem by making it dependent on the framerate.

Link to comment
Share on other sites

No, what xEvilReeperx means is to have two separate animation clips. One with your loop and the light on, the other simply with the light off - can be single keyframe. Using animation.blend, rather than play, you can set it to blend over right to the animation with the off state. It's rather cunning! Shout if that doesn't make sense, though

Link to comment
Share on other sites

No, what xEvilReeperx means is to have two separate animation clips. One with your loop and the light on, the other simply with the light off - can be single keyframe. Using animation.blend, rather than play, you can set it to blend over right to the animation with the off state. It's rather cunning! Shout if that doesn't make sense, though

No, I understood xEvilReeperx - it just seems rather redundant to have an empty animation.

Link to comment
Share on other sites

It's not empty, it's a single frame clip that disables the light (you can animate Renderer's "enabled" property). It's a bit nicer than doing it (entirely) in code

I see what you mean. It's not ideal, but barring further input by MOARdV, it'll have to do.

Also, these LED lights are just emissive animations:

iAYWIqT.gif

Link to comment
Share on other sites

It's not empty, it's a single frame clip that disables the light (you can animate Renderer's "enabled" property). It's a bit nicer than doing it (entirely) in code

Forgive my Unity ignorance - you are saying I would play the "off animation" when I want to stop the blinking lights. I get that part. Do I need to stop the "blinking" animation as well? (and vice-versa when I want to restart the blinking animation?) And what do you mean by "animate Renderer's 'enabled' property"?

Although lo-fi also suggests using blend(), and I see there's a cross-fade method as well.

Link to comment
Share on other sites

Forgive my Unity ignorance - you are saying I would play the "off animation" when I want to stop the blinking lights. I get that part. Do I need to stop the "blinking" animation as well? (and vice-versa when I want to restart the blinking animation?) And what do you mean by "animate Renderer's 'enabled' property"?

No, don't need to stop the blinking animation. They wouldn't be visible anyway.

As to animating Renderer enabled: just like you can create an AnimationClip out of keyframes of Transform position, rotation, various material properties etc, so too can you create keyframes for Renderer.enabled

Re: blend, crossfade: those are for mixing animations. Probably not applicable in this instance

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...