Unity: Why does my animation only work sometimes? - unity3d

I tried to transition into a scene with a fade in/fade out animation. Basically just changing the alpha value of an Image.
As reference: I followed the tutorial of Brackeys here https://www.youtube.com/watch?v=CE9VOZivb3I - However it did not work for me.
So I tried to do step one which is blending into a scene when started on my own.
I set up a SceneLoader with an Image:
I animated the alpha value change for a StartScene animation and added the Controller to the Canvas:
The Animator looks as following:
It worked a few times but stopped working suddenly. I'm pretty sure I did not change settings of the object.
When I prefabed it and put it on other scenes, it also did not work accordingly.
I have multiple UI Elements in my scenes, so I put the SceneLoader at the very bottom of the Hierarchy.
Any idea what I'm doing wrong here?

I suggest you not to use the canvas but the panel instead. You can create 3 animations in the panel, one for fading in, one for fading out, and one for idle ( with transparent panel). Once you have done this you can set the fade-in for the first state and add a transition for the idle one without conditions with "Has exit time" with the duration of your animation. Then you can set a transition from idle to fade-out with a trigger. In the code, you will simply animator.SetTrigger(fading); and it should work like that. Remember to uncheck the loop in fading animations and check it in the idle one.

Related

Unity 2D: how to play 2 animations at once?

so recently I started working with Unity animator, pretty cool, but got an issue.
I want to play "walk" animation and whenever preson gets a gun play another "hold" animation.
I tried to make 2 layers with usual walking and beneath it gun holding animation, but it just overrides with gun holding animation.
Any ideas?
Edit: screenies
As KinyL states, you need to add an Avatar Mask to the upper body layer. In the Mask, uncheck the lower body elements and you'll be good to go.

Unity build of my game wont play a default animation

I have an issue with the current build and run operation on a project I'm making, where the default animation of a "scene" animator wont play, while in the editor in the same build, it does play.
This question that has a related title doesnt apply for my issue.
Unity Default Animation Not Playing
Moreover, just after I check play on the editor to check if everything works properly, I press ctrl+b to build and run, and in-game this default animation wont play, for no apparent reason.
Everything is set properly, , the speed of the animation, the animator, etc; everything works well in the editor and inside the editor's game window, even the game's sounds run in the background. But for a reason I can't seem to find, it will not play in the build. I'm not affecting anything else than a image component to make this "scene"
animation.
Detail of the animation issue: The animation is just a sliding diagonally-rotated black image, occupying all the game screen, that gradually moves to the right until it cant be seen in the screen. For some reason, this is not playing, making the screen be pitch black.
Any ideas will help, the game is an exam.
Problem: I was using an animator override controller, in version 2019.2.17f1.
Looks like the animation override controller had unsolved bugs for that version that are not visible in the editor; or something may have got set incorrectly, despite my repeated checks on this simple animator window.
Solution: I attempted to switch back to the normal animator component just to test, and everything works perfectly as intended; the animation plays.
Any comments/critiques regarding the problem/solution are very much welcome

Unity Animation is not playing after i animated material, also animator gets disabled when i play animation clip

Here have a look at this screen recording (https://youtu.be/PvAt_t0NdQk). What am I doing wrong? I have selected prefab and working on it directly. I animated the material of the object I want it to fade out, so I animated the material and it works but then it doesn't after I unclick from it. Also, I have noticed the Animator component is getting disabled when I play the animation clip.
I fixed it by changing to mode to Fade. I don't know why but it was suppose to change itself in the animation but it doesn't.

how to reference an "armature action" of a bow using code?

I'm trying to make a bow and arrow game. I downloaded a bow that has an animation(?) on it where the string is pulled back.
See:
I want to make a script that triggers that animation (shown on bottom-right of my gif) when Player left clicks. But I don't know how to reference the animation.
Is it something like _anim = GetComponent<Animator>(); and then animation.Play? I cannot tell what the name of the animation even is to do this.
Further.. it would be awesome to be able to control the animation's length depending on how long the user has held down the button, rather than playing it in full even if user only taps left click. I'm not sure how that would be achieved?
Ok, the question seems short but the solution will be long and you need to do a bit of learning. So, let's go through your question step by step.
I downloaded a bow that has an animation(?)
Yes, it is a 3D bow model with an animation in it.
I want to make a script that triggers that animation (shown on
bottom-right of my gif) when Player left clicks. But I don't know
how to reference the animation.
In order to trigger that animation, you need an Animator Controller attached to the bow model instance. Then you can click that Animator Controller to open its panel. After opening the panel, you can simply drag and drop your animation there. When you first drop your animation, it will be the default animation state. However, if you don't want to trigger the animation immediately, I would suggest you to create an empty state and make a transition to the bow animation.
Is it something like _anim = GetComponent(); and then
animation.Play?
More or less like this, but you should check the documentation for better understanding, this documentation explains it well and has a really good example for your use case.
I cannot tell what the name of the animation even is to do this.
Once you drag and drop the animation to the panel, you will see the name of the animation to use in the script.
Further.. it would be awesome to be able to control the animation's
length depending on how long the user has held down the button,
rather than playing it in full even if user only taps left click.
I'm not sure how that would be achieved?
There are many ways to play with animations, for example, you can set an animation parameter to stay in the animation state. Furthermore, you can also disable the Has Exit Time value from the transition to make it stop the animation immediately after the user stops holding the button.
Overall, when it comes to animations, Unity is quite powerful and my suggestion would be read the documentation and watch a couple of tutorials.
Hope this helps.

Sprite Animation flickering in unity

I'm trying to play sprite animation in unity, it is playing but when ut is playing the animation is flickering
How to solve this issue
I had a sprite animation on layer 0 placed on top of a background sprite image and got the flickering as well.
Change the sprite "order in layer" property to 1 (and leave your background sprite set to "order in layer" zero.
Flashing went away.
I had same problem. I fixed mine by adjusting the sorting layer. The flickering is caused by overlapping sprite.
So, your post came up in the searches. I was having a similar issue. For me, the animation would play, but there was a couple of bad frames/sprites that would be there as far as 'in' the animation, but they just weren't showing on screen. I could click on the frame image and it would show, but during animation it would disappear, causing the flashes.
But, by having the pop-out animation window open that can play frame by frame, I could figure out where the flash was. (Again, everything appears correct. Double-checked that it was set up the same as all others.) If you also watch the inspector window with the object selected, you can see the name of each animation frame as it goes by. So I did the frame-by-frame and saw that in two spots it said 'Sprite Missing'.
I figured they were just corrupted so I deleted them. But, the problem was still there (indicating that it wasn't an image issue.) Surprisingly though, when I tried dragging just those two images back in, everything worked fine. Who knows why 🤷‍♂️
Anyway, mine at least was a simple fixed once I kind of figured out where the issue was at. so, hopefully this might help someone else out at some point.