Animation stuck at the beginning unity - unity3d

Ok so I have a few animations on my character in unity, but when I hit play, in the Animator tab I see that the blue bar remains at the beginning. Although, if (while I am still in playmode) I uncheck the boxes for my boolean variables in animator, it works correctly. This is my code, please help:
{
foreach(AnimatorControllerParameter parameter in shaggyAnim.parameters)
{
shaggyAnim.SetBool (parameter.name, false);//stops the other animations
shaggyAnim.SetBool(anim, true);//plays the wanted animation
//for each animation I declared a bool variable inside unity animator
}
}```

Why don't you just set the Default State? You don't need to check all the animation parameters at the beginning. Just set the animation which you want as default state and unity will play that animation only at the beginning. Just make sure all other parameters in transition are false.

Related

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.

Property "Raycast target" does not work in animation

TL;DR - Property "Raycast target" (from Image in Canvas) is successfully animated but has no real effect (passes events through itself when it should not).
I have Image in Canvas that I am animating. In animation I change "Raycast target" property so I can interact with buttons behind after the animation ends.
Propery changes in inspector, but has no effect - I can press buttons behind when animation hasn't finished yet and "Raycast target" is "True".
When I do not use animation and change propery directly through script - everything works as expected.
What am I missing?
My Scene:
Canvas
|-Buttons
|-Image (Foreground, Animated)
My animated Image:
My Animation:
Note: "Write Defaults" in animator does not affect anything.
Unity 2020.3.8.f1 LTS
I think raycastTarget just enables Unity to consider this object for raycasting events. Turning it on or off may not make any difference to the elements behind it. I am not sure of it without testing but they have stated a single line for the raycastTarget property in the Documentation which does not help too much about this case.
I am sure that there is a blockRaycasts property on CanvasGroup component in Unity. Add this component to the object and it should block the elements behind it if it has a graphic (Image or something) attached to it.
I have not found solution, so I fixed problem through script. It checks animator state and manually changes property. In my case I have "Idle" state that is active when animation is not playing.
public class RaycastTargetFix : StateMachineBehaviour
{
public string interactableState = "Idle";
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
var image = animator.GetComponent<Image>();
if (image) image.raycastTarget = !stateInfo.IsName(interactableState);
}
}
Script needs to be added to animator:
Of course raycastTarget property should not be animated, otherwise it cannot be changed through script.

Unity: Why does my animation only work sometimes?

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.

Unity animation shows it is being played, while it isn't played at all

I have my main character. It has animator attached to it. Animator on it's own has boolean variable "IsWalking" which is true only while button W is down. However, I got new animations from my designer. The animations were made in Mixamo, using the body of the main character. When I added them in unity and made the transition "ifs" a problem occurred. My main character animator loads the animation as if it is being played, yet, nothing happens to the character he stays paralysed on place. Any ideas? I tried "apply rood motion", it didn't help.

Entry Animation does not play again when Animator is disabled then enabled

I have an animation I created called "FallingTile" that plays on my object on the Entry phase of the Animator. The problem is, because I need to change the color of the object throughout my game I need to toggle the Animator on only when it's being used, and then disable it again (this seems to be the only way to be able to change the object's color still). The first time the object's Animator is enabled the "FallingTile" effect runs smoothly and the Animator is disabled properly. However if I try to trigger the same object to animate again it will not do so. I don't believe Entry is only ran the first time the Animator is enabled because I use the same type of system for fading in/out background colors. Here's what I'm trying:
public void FallingTilesAnimation() {
Anim.enabled = true;
Invoke ("DisableAnimator", 1.1f);
}
private void DisableAnimator() {
Anim.enabled = false;
TileImage.material = null;
}
I also tried setting the Animator state back to Idle before disabling it to see if maybe that was the issue but it didn't seem to help.
edit: Probably worth noting my object starts with no material and one is added/manipulated in the FallingTile animation. It should go back to having no material after the animation ends to "reset" to the pre-animation object.
edit2: I realized it may be that Entry only runs the first time the Animator is enabled. For changing background colors I'm changing the active state of the entire object - setting the object to active likely triggers Entry again but enabling the Animator a second time may not?