Flare/Flutter: How to reset the progress of an animation before starting it? - flutter

I have a Flare file with 3 animations contained within it, all in the same artboard. I understand that when switching between animations, Flare will mix the animations together by default, and that playing one animation will not reset the relevant nodes values back to what they were on frame 0 in the editor. That is the behavior I would like to achieve: when playing a new animation, I would like the previous animation to stop completely (don't mix them at all) and for the incoming animation to start at the very beginning with all its default values.
The use case is this:
Play an animation where, say, the opacity of a shape goes down to zero
Play a different animation that uses the shape from above, but in the Flare editor its opacity is 1 at the start of the animation
Desired result: the new animation resets the opacity of the shape and then begins and plays like normal
Actual result: since the previous animation changed the shape's opacity, the new animation will use the shape how it is instead of how it was created in the editor
For my question as explained on GitHub you can look at the end of the thread on this issue (has gifs): https://github.com/2d-inc/Flare-Flutter/issues/14
In the above thread, Luigi Rosso mentions "re-instancing" the artboard. Does anyone know what he means by this and how to do it? I have tried several methods of doing this such as the makeInstance methods found on classes such as FlutterActorArtboard, ActorNode and some others (there are a few variants of the makeInstance method but they are all similarly named and return a new artboard. However, I had no luck with replacing the current instance of my artboard in a FlareController implementation so far.
I have also tried to manually loop through all of the ActorNodes of the artboard and first saving their initial values and then copying the saved values to the artboard every time a new animation is played, but this seemed to break things pretty badly (the animation was unrecognizable and just didn't play correctly after that, so I must have done something wrong. Or I'm resetting the wrong values).
Any help is appreciated, thanks!

For playing a different animation on a shape and resetting its opacity, you can access the opacity of the node at runtime with:
ActorNode myNode = _artboard.getNode("nodeString");
myNode.opacity = 0.00;
As outlined here in the manual.
More simply, in the new animation, you can set a keyframe in the Rive/Flare editor for the opacity to be 1 at the start of the new animation, so that when it plays the animation from the beginning its opacity will be reset to 1.
For playing one animation, then overriding it completely when the next animation plays you can extend the FlareController and create a custom animation controller to do this in the advance method.
Here's a quick and dirty example (not best practices) to give you an idea of using advance:
https://gist.github.com/she-who-codes/85d8f0da97abfc3ecc43b1cb470e9c29
https://gist.github.com/she-who-codes/ce633204cd2d4babfe9a5b54e34ca63d

Related

Having issues with animations of objects that come from a prefab

So let me preface this that, i am very new to unity this is my first week actually lol and i couldnt exactly find anything that would answer my question.
Anyways, i have this like thwomp object that has 3 animation states crush, reset, and wait. and it goes up and down as you would see it normally just on a timer because of the wait. it is done by adding the position property and then moving the y up and down. pretty simple i think, couldnt think of anything better. it works perfectly just like i want it too.
but when i made it a prefab and try to make more of them, the animation for the copies have the same x and y as the original. so like even though i can change the base like default positioning of them whenever the game starts and the animation plays they just perfectly overlap with the first original one that the prefab was made with. when i try to change the x coordinate on the copies animation it updates the x coordinates for all them. this happens even when i delete the prefab and just manually make copies with ctrl + d as well (im not sure if this any different?) . i assume this is because they all share the same 3 animations so when you change the animation it changes it for all them and that makes sense.
but i really dont want to make 3 seperate animations for each replica thwomp i make, i feel like there definitely has to be a better way. my original thought of how it would be was they would share the same animation, but like within the object its self the animation values like the position are exclusive to the object so they could differ inbetween each one.
ill include a link a picture to like further convey what i have going on here so its easier to understand. https://imgur.com/a/78q6VCI
You want to change the localPosition not the world position. This thread has a little discussion about it but basically you need to use the x, y, z you get from the Animator as an offset to localPosition.
Pseudo code:
transform.localPosition.y += animators position.y
https://forum.unity.com/threads/playing-animation-local-to-position-in-unity.53832/#post-489101
Special note: Using an animator is pretty heavy. For simple stuff like this I would suggest just scripting it.

How to control a Flutter/Flare animation based on timer?

I want to accomplish the following:
Based on a variable timer (hours, minutes and seconds) three goals have to be fulfilled: Received, Preparing and Ready.
Example: when the timer is about 15 seconds, the lines and the dot have to be filled with the orange color -- just in a linear way.
So far, I have accomplished this:
Where:
The first line is made with Flutter CustomPainter
The second line is made with Flare, see:https://www.2dimensions.com/a/JohanWalhout/files/flare/fill-line/embed
Now, I'm facing the follow problems:
How can I animate the Flutter CustomPainter like the Flare animation?
or:
How can I animate the Flare animation where the animation duration is the time it takes to fill the orange color?
Please, see the complete app in the following repo: https://github.com/LiveLikeCounter/Flutter-Food-Delivery
Flare and CustomPainter are two completely different things. CustomPainter is a widget that comes with the Flutter SDK and Flare is an vector animation tool by 2Dimensions. They cannot change/manipulate each other in any way.
How can I animate the Flare animation where the animation duration is
the time it takes to fill the orange color?
If you want to stick to Flare then you can separately create the fill animation and use FlareController to play the animation as and when you wish.
Just remember the name you give it e.g In this case, it is 'home-on' and 'home-off'
Refer to this blog before you start to code/design:
https://medium.com/2dimensions/building-a-responsive-house-with-flare-flutter-31af823ba805
However, it is still recommended that you use AnimationController and some variables to get full control of your widgets instead of relying on any third party animation tool.
For the custom painter you can use a basic canvas.drawLine and make sure your shouldRepaint returns true when ever the end line position changed. The end position will be relative to the timer and what you consider a line to be full.
For the Flare animation you have to create a controller that will take in the time on every timer tick you want to animate, then set your current playback time for you artboard equal to the position you want for that time. 15second = 100% in your case so your applied time should be the full animationDuration, 7.5 you'll set it to animationDuration * 0.5, so you have to figure your formula out for that.
You can use my SwipeAdvanceController from SmartFlare then call updateSwipePosition using Fake values that will represent your "swipe". The controller will advance from 0 to 100% of the animation depending on how you swipe over the animation allowing you to create sliders, etc using Flare so it should work with this by passing in fake touch positions to emulate.

Unity - Animation Loops?

I am using an FBX 3D object file as a game object in my project which have further sub assemblies. Now i want to animate a part of the assembly.
I followed this process:
Select the part which I want to animate.
In the animation panel create one animation.
Add property > transform > position
Using pivot, i move that part to the location where I want to animate.
Challenges
Animate in loop. Moreover if I Select animation file, it does not show Wrap mode
( 1. I don't want any loops in my animation, even after deselecting loop-time it does loop. - I dont know why?
It is animating in reverse. suppose if the object needs to go from position x:3 to position x:8 but it goes from position x:8 to position x:3
the above point happens in loop. just like a ping pong)
Animates in reverse.
I take the whole animation as one loop i.e Part comes out of assembly and goes back and repeating for infinite time.
I want to stop the animation till the point it comes out.
Any help will be appreciated

Making multiple objects with the same shader fade at different times

I have a death transformation for one of my GameObjects which goes from a spherical ball to a bunch of small individual blocks. Each of these blocks I want to fade at different times but since they all use the same shader I cannot seem to figure out how to make all of them not fade out at the same time.
This first picture is the Spherical Ball in its first step for when it turns from a spherical ball to a Minecraft'ish looking block ball and to the right of it is one of the blocks that make up the Minecraft'ish looking ball shown by the red arrow.
Now this is my Inspector for one of the little blocks that make up the Minecraft'ish looking ball.
I have an arrow pointing to what makes the object fade but that is globally across all of the blocks since they use the same shader. Is it possible to have each block fade separately or am I stuck and need to find a new disappear act for the little block dudes?
You need to modify the material property by script at runtime, and you need to do it through the Renderer.material property. When you access Renderer.material, Unity will automatically create a copy of the material for you that is handled separately -- including getting its own draw call, if you care about performance. You can tell this has happened because the material name in the renderer will change to "Materialname (Instance)".
Set the material's fade property using Renderer.material.SetFloat() (or whatever the appropriate Set... function is). Unfortunately the property's name isn't "Fade Factor". You can find the property's name by looking at the shader script, or by switching the inspector to debug mode and digging through the Saved Properties array for one that looks right.

How can I chain animations in iPhone-OS?

I want to do some sophisticated animations. But I only know how to animate a block of changes. Is there a way to chain animations, so that I could for example make changes A -> B -> C -> D -> E -> F (and so on), while the core-animation waits until each animation has finished and then proceeds to the next one?
In particular, I want to do this: I have an UIImageView that shows a cube.
Phase 1) Cube is flat on the floor
Phase 2) Cube rotates slightly to left, while the rotation origin is in bottom left.
Phase 3) Cube rotates slightly to right, while the rotation origin is in the bottom right.
These phases repeat 10 times, and stop at Phase 1). Also, the wiggling becomes lesser with time.
I know how to animate ONE change in a block, but how could I do such a repeating-thing with some sophisticated code in between? It's not the same thing over time. It changes, since the wiggling becomes lesser and lesser until it stops.
Assuming you're using UIView animation...
You can provide an animation 'stopped' method that gets called when an animation is actually finished (check out setAnimationDelegate). So you can have an array of animations queued up and ready to go. Set the delegate then kick off the first animation. When it ends it calls the setAnimationDidStopSelector method (making sure to check the finished flag to make sure it's really done and not just paused). You can also pass along an animation context which could be the index in your queue of animations. It can also be a data structure that contains counters so you can adjust the animation values through each cycle.
So then it's just a matter of waiting for one to be done then kicking off the next one taken off the queue.
The same method applies if you're using other types of animation. You just need to set up your data structures so it knows what to do after each one ends.
You'll need to setup an animation delegate inside of your animation blocks. See setAnimationDelegate in the UIView documentation for all the details.
In essence your delegate can be notified whenever an animation ends. Use the context parameter to determine what step in your animation is currently ending (Phase 1, Phase 2, etc)
This strategy should allow you to chain together as many animation blocks as you want.
I think the answer to your question is that you need to get more specification on what you want to do. You clearly have an idea in mind, but more specification of details will help you answer your own question.