Hello everyone! I just released part 2 of this video! It’s an independent animation scripting system that works with layers and animation locking (and is very easy to use). Go check it out! ua-cam.com/video/Db88Bo8sZpA/v-deo.html
@@maxgordon3194 ChangeAnimation is a custom function he created that can only recieve a string, but It's all about the CrossFade call in the Unity Animator API that you can pass it either the animation state name (as a string) or the state hash (as an int)
@@maxgordon3194 ChangeAnimation is a custom function that he created that calls the CrossFade from Unity animator API and can only recieve a string, but In CrossFade function you can pass it either the animation state name (as a string) or the state hash (as an integer).
@@maxgordon3194 ChangeAnimation is a custom function that he created that calls the CrossFade from Unity animator API and can only recieve a string, but In CrossFade function you can pass it either the animation state name (as a string) or the state hash (as an integer).
@@maxgordon3194 'ChangeAnimation' is a function created by him that receives a string, but this functions basically just call de Unity Animator api "CrossFade" wich can receive a id as number, so it's all up to you
It's actually pretty smart but also simple. I mean, even if you use the animator transitions and variables, you need to change them by script, so why not do all the rest too? You opened my eyes, thank you!
Unity actually has a built-in feature just for this! It's called an Avatar Mask. Where you can select different parts of the body to only be affected by a certain layer. I'm actually currently working on making a video for that right now :)
I think "dont use the unity animator, use code instead!" rolls off the tongue better than "Dont use the unitor animators transitions and parameters to control which animation is playing, use code instead!"
@@jacklivingstone1882 dude, i know everyone figured this out, but i have to admit the fun fact that i do this myself, this approach immediately seemed more tame and controlled to me when learning unity.
Does this work with BlendTrees as well? All of my characters directional movement is handled in a BlendTree (forward, back, right, left, ForwardRight, ForwardLeft, etc)
Feel free to correct me on this. I believe blend trees act like any other Unity animator state. So you should be able to run Animator.Crossfade("Blend Tree Name")
Hello there, I wanted to organize my Animations with state machines. Now the Animation won't switch anymore. I think it's because it's not in the "area" anymore. Does anyone know if it's possible to switch between state machines and how? Thank you for any answers! Edit: I'm able to access the AnimatorController and through that the Base Layer as an AnimatorStateMachine. How could I switch the StateMachine...?
i did this it seems alot cleaner but i have problem when i press left and right (a and d) for movement the animations bug out and it starts playing the running animation but with input.getaxisraw("horizontal") it should equate to 0? or when i fast tap a and d the player would walk but in the idle animation very weird
Hey, I encountered an error where the attack animation will stop playing after the first hit. I followed the tutorial shown in the video but it is not working. :(
Sorry you're having problems! I might be able to help out with a bit more context. I'll also add we worked on making a dedicated plugin for Unity for animator coding following this video, where you hardly need to set anything up, might be worth checking out ua-cam.com/video/9tvDtS1vYuM/v-deo.html
@@SmallHedgeHQ Thank you for replying! The hierarchy for my player is "Player > Player Model", my player controller script is attached to the Player game object and the animator component is attached to the Player Model game object. As shown in the video, its "GetComponent" and since my animator component is attached in the child object I used "GetComponentInChildren"
Hmm bizarre! I’ll try to troubleshoot everything that comes to mind. 1. When calling Animator.Play(“”), the string needs to be exactly the same as the Animator state name (not the animation clip name) 2. It needs to be on the right animation layer (default is 0) 3. The Animator itself has no transition lines 4. Ensure that GetComponentInChildren() is getting the right animator component (print animator.GetInstanceId() and go to the inspector and enter debug mode in the top right, make sure they match. Or just call animator.name) 5. After animator.Crossfade() (with crossfade = 0) print animator.Update() then animator.GetCurrentAnimatorStateInfo.IsName() then test if it is actually playing the animation 6. Check if the animator component has a valid animator controller Hope that helps! If not, flick through the code and we might be able to spot something.
Yeah I suppose it depends on your ideal workflow. Whether to use the animator as a visual fsm or write all the conditions through code. In a lot of cases you could use a bit of both.
I want to ask what happens if it applies to thousands of enemies? I want to ask if the animation clip when attacking has a length of about 2 seconds, do we have to check to run the entire animation before switching to Idle mode?
That was actually a problem with this workflow. We actually solved it in this video, where the concepts from this video was turned into a self-sufficient plugin ua-cam.com/video/9tvDtS1vYuM/v-deo.htmlsi=ToetMGz0N_Y1ih0G
I suppose If you have say 10 animation states and want to join them all together that would be 45 animation transitions lol. It’s a Fibonacci sequence.
can you tell me how to use this technique as a animation override controller, like if there are multiple animation sets with the same animation names but different poses. like holding a hammer, or holding a gun etc. both have same number of animations but the animation data is different like the idle for holding a hammer is different and idle for holding a gun is different etc, if you cant make a tutorial can someone give me an overview of how to achieve this?
I think I understand. You’re wanting to work with layers. Such as the bottom half of the body is idle but the top half is swing a hammer. I would recommend watching my latest video of animation scripting as I go through this step by step ua-cam.com/video/Db88Bo8sZpA/v-deo.html
@@SmallHedgeHQ no what I mean is we got three or more weapons or so. like a shotgun, a melee weapon, a assault rifle etc. each of them has its own animation set for example: idle anim while holding hammer, attacking with it etc. same goes for the next one like switching weapon to shotgun or rifle, then their own animation sets and so on being applied to the same character skeleton. how can we achieve that. also ill check your latest video out.
@@maxgordon3194 Right. There are two ways this can be approached: Using one animation controller and using many animation controllers. Setup: Have an animator component attached to the player. Put every weapon as a child of the player in the appropiate rigging position and disable all of them. The animation controllers have two layers: Upper Body and Lower Body. One Animation Controller: The Upper Body layer is where you place every single player movement animation (idle, move, jump etc) and every single weapon animation ever (hammer idle, hammer swing, shotgun idle, shotgun shoot etc). The Lower Body layer is where you put all player movement animations that use the legs. Use the AnimatorBrain script as in the mentioned video. To disable/enable weapons when you switch you can either: enable/disable in the animations themselves (at the end of the put away animation it disables it and at the start of the pull out animation enables it as a keyframe) or enable/disable them in script. Many Animation Controllers Have an animation controller for each weapon. The Upper Body layer for each animation controller contains exactly the same as ^ except it only contains animations for the current weapon. Then when you come to switch weapons, disable the current weapon and enable the next weapon (as described in ^) and swap the animation controller in the animator to applicable animation controller. Great thing is you can make each animation controller visually identical (same state names so Animation.Crossfade() will work) but the states hold the applicable weapon animation. For using One Animation Controller its advantage is Animation.Crossfade() works when swapping weapons. The advantage to Many Animation Controllers is adding more weapons can be done at runtime procedurally and is easier to handle as the project scales but beware, making a change would mean making that same change in every animation controller.
@@SmallHedgeHQ thanks I'll give this a try. in the future if you make more animation related videos do keep fps animation setups on your list if you make more of these someday. 😃
for the idle animation, wouldn't it just be easy to set the first value of currentIdle to 1, check if it's over 7 and loop it back to 1 and just have the last else call ChangeAnimation($"Idle {currentIdle}"); ??? Just kinda feels like there's no reason to add extra steps for something relatively simple. EDIT: And someone beat me to it a little further down like 3 weeks ago, sorry.
Yeah you’re right, would be a lot simpler. I actually corrected this in the latest video where we instead used enum arrays and hashes to play animation.
This has some drawbacks though. Consider large game with large codebase with lot of legacy code, or case when you even don't have access to some code. Then you are porting some features and in that case using animator is really convenient. Otherwise your visuals are tightly bound to code, which is not good. Or you can't give some tasks to tech / ui artists who are not that familiar with code.
It's good to know that there's way to make move between animation with out animator traction However I prefer to use the animator traction in my game But if it's system that I'm not able to do with the animator it may use this system for reference. That's my sounds weird to you but i personally prefer to not make the wail animator system with code
I suppose it comes down to what your default is and how you arrive at solutions. With game development, there’s an infinite amount of ways to do the same thing. It’s just about finding the workflow which suits you best.
Hello everyone! I just released part 2 of this video! It’s an independent animation scripting system that works with layers and animation locking (and is very easy to use). Go check it out!
ua-cam.com/video/Db88Bo8sZpA/v-deo.html
(timestamp 8:45)
instead of a switch on check idle:
string anim = $"Idle {currentIdle + 1}"
ChangeAnimation(anim)
in ChangeAnimation(anim) , are we supposed to write the name of the animation in anim or give its number?
@@maxgordon3194 ChangeAnimation is a custom function he created that can only recieve a string, but It's all about the CrossFade call in the Unity Animator API that you can pass it either the animation state name (as a string) or the state hash (as an int)
@@maxgordon3194 ChangeAnimation is a custom function that he created that calls the CrossFade from Unity animator API and can only recieve a string, but In CrossFade function you can pass it either the animation state name (as a string) or the state hash (as an integer).
@@maxgordon3194 ChangeAnimation is a custom function that he created that calls the CrossFade from Unity animator API and can only recieve a string, but In CrossFade function you can pass it either the animation state name (as a string) or the state hash (as an integer).
@@maxgordon3194 'ChangeAnimation' is a function created by him that receives a string, but this functions basically just call de Unity Animator api "CrossFade" wich can receive a id as number, so it's all up to you
watching someone code like this is satisfying since im learning to code as well
It's actually pretty smart but also simple. I mean, even if you use the animator transitions and variables, you need to change them by script, so why not do all the rest too? You opened my eyes, thank you!
I'd say animator is the better approach though, its a matter of learning how to properly use it if you get into a spagetti mess
Nice video, explained really well. Keep it up!
Thank you! Great to help out
I liked the background SFX you used.
Perfect explanation and pacing. I learned a lot here, thank you!
Your welcome! Glad I can help out!
omg I always hated to animated in the animator now I can do it through code TYSM!
Ok but what about movement in the diagonal directions? Like do you need 4 more animations for that or is there a way to blend the 4 you already have?
How do you make this work with layers?
Like i want the punch just to affect the upper body and at the same time i have the walk interact with the legs
Unity actually has a built-in feature just for this! It's called an Avatar Mask. Where you can select different parts of the body to only be affected by a certain layer. I'm actually currently working on making a video for that right now :)
@@SmallHedgeHQ awesome, thanks
this is genius! thanks for the video
Author: "Don't use the Unity Animator"
Also author: * uses Unity Animator *
😄
xD
I think "dont use the unity animator, use code instead!" rolls off the tongue better than "Dont use the unitor animators transitions and parameters to control which animation is playing, use code instead!"
@@jacklivingstone1882 dude, i know everyone figured this out, but i have to admit the fun fact that i do this myself, this approach immediately seemed more tame and controlled to me when learning unity.
Good job, man!
Escape from animator hell, into a new code hell
Does this work with BlendTrees as well? All of my characters directional movement is handled in a BlendTree (forward, back, right, left, ForwardRight, ForwardLeft, etc)
Feel free to correct me on this. I believe blend trees act like any other Unity animator state. So you should be able to run Animator.Crossfade("Blend Tree Name")
Hello there, I wanted to organize my Animations with state machines.
Now the Animation won't switch anymore.
I think it's because it's not in the "area" anymore.
Does anyone know if it's possible to switch between state machines and how?
Thank you for any answers!
Edit:
I'm able to access the AnimatorController and through that the Base Layer as an AnimatorStateMachine.
How could I switch the StateMachine...?
i did this it seems alot cleaner but i have problem when i press left and right (a and d) for movement the animations bug out and it starts playing the running animation but with input.getaxisraw("horizontal") it should equate to 0? or when i fast tap a and d the player would walk but in the idle animation very weird
Amazing video! Much appreciated works great.💯
From where did you get " GetComponent"
GetComponent is a function tied to the GameObject class! It allows you to get any component exisiting in the inspector.
So well explained, i'll subscribe
Hey, I encountered an error where the attack animation will stop playing after the first hit. I followed the tutorial shown in the video but it is not working. :(
Sorry you're having problems! I might be able to help out with a bit more context. I'll also add we worked on making a dedicated plugin for Unity for animator coding following this video, where you hardly need to set anything up, might be worth checking out ua-cam.com/video/9tvDtS1vYuM/v-deo.html
@@SmallHedgeHQ Thank you for replying! The hierarchy for my player is "Player > Player Model", my player controller script is attached to the Player game object and the animator component is attached to the Player Model game object. As shown in the video, its "GetComponent" and since my animator component is attached in the child object I used "GetComponentInChildren"
Hmm bizarre! I’ll try to troubleshoot everything that comes to mind.
1. When calling Animator.Play(“”), the string needs to be exactly the same as the Animator state name (not the animation clip name)
2. It needs to be on the right animation layer (default is 0)
3. The Animator itself has no transition lines
4. Ensure that GetComponentInChildren() is getting the right animator component (print animator.GetInstanceId() and go to the inspector and enter debug mode in the top right, make sure they match. Or just call animator.name)
5. After animator.Crossfade() (with crossfade = 0) print animator.Update() then animator.GetCurrentAnimatorStateInfo.IsName() then test if it is actually playing the animation
6. Check if the animator component has a valid animator controller
Hope that helps! If not, flick through the code and we might be able to spot something.
Meanwhile Unreal Engine Animation Blueprint just being superior
@@alvin4422 i think blueprint can be used along with c++ code? how would Abstraction, Inheritance, polymorphism and encapsulation not apply to c++?
@@lokosstratos7192I’ll play your game, toss the link.
How different it is? I havent studied that far.
@@zanagi As far as I know it's got visual scripting kinda thing so you can run your logic inside of it.
I think Animancer could solve all problems, also would suggest using fsm in code
Yeah I suppose it depends on your ideal workflow. Whether to use the animator as a visual fsm or write all the conditions through code. In a lot of cases you could use a bit of both.
I want to ask what happens if it applies to thousands of enemies?
I want to ask if the animation clip when attacking has a length of about 2 seconds, do we have to check to run the entire animation before switching to Idle mode?
That was actually a problem with this workflow. We actually solved it in this video, where the concepts from this video was turned into a self-sufficient plugin ua-cam.com/video/9tvDtS1vYuM/v-deo.htmlsi=ToetMGz0N_Y1ih0G
Thanks!, New Zealand??
Oh yeah😁
Great video bro
The cleanest coder Niceee
Can you do a tutorial on animation with weapons using these systems
Actually that’s the next video! Stay tuned
@@SmallHedgeHQ Oh! Sick will defo check
but I can't code...
Why would you have so many animation transitions on a single layer though?
I suppose If you have say 10 animation states and want to join them all together that would be 45 animation transitions lol. It’s a Fibonacci sequence.
can you tell me how to use this technique as a animation override controller, like if there are multiple animation sets with the same animation names but different poses. like holding a hammer, or holding a gun etc. both have same number of animations but the animation data is different like the idle for holding a hammer is different and idle for holding a gun is different etc, if you cant make a tutorial can someone give me an overview of how to achieve this?
I think I understand. You’re wanting to work with layers. Such as the bottom half of the body is idle but the top half is swing a hammer. I would recommend watching my latest video of animation scripting as I go through this step by step
ua-cam.com/video/Db88Bo8sZpA/v-deo.html
@@SmallHedgeHQ no what I mean is we got three or more weapons or so. like a shotgun, a melee weapon, a assault rifle etc. each of them has its own animation set for example: idle anim while holding hammer, attacking with it etc. same goes for the next one like switching weapon to shotgun or rifle, then their own animation sets and so on being applied to the same character skeleton. how can we achieve that. also ill check your latest video out.
@@maxgordon3194 Right. There are two ways this can be approached: Using one animation controller and using many animation controllers.
Setup:
Have an animator component attached to the player. Put every weapon as a child of the player in the appropiate rigging position and disable all of them. The animation controllers have two layers: Upper Body and Lower Body.
One Animation Controller:
The Upper Body layer is where you place every single player movement animation (idle, move, jump etc) and every single weapon animation ever (hammer idle, hammer swing, shotgun idle, shotgun shoot etc). The Lower Body layer is where you put all player movement animations that use the legs. Use the AnimatorBrain script as in the mentioned video. To disable/enable weapons when you switch you can either: enable/disable in the animations themselves (at the end of the put away animation it disables it and at the start of the pull out animation enables it as a keyframe) or enable/disable them in script.
Many Animation Controllers
Have an animation controller for each weapon. The Upper Body layer for each animation controller contains exactly the same as ^ except it only contains animations for the current weapon. Then when you come to switch weapons, disable the current weapon and enable the next weapon (as described in ^) and swap the animation controller in the animator to applicable animation controller. Great thing is you can make each animation controller visually identical (same state names so Animation.Crossfade() will work) but the states hold the applicable weapon animation.
For using One Animation Controller its advantage is Animation.Crossfade() works when swapping weapons. The advantage to Many Animation Controllers is adding more weapons can be done at runtime procedurally and is easier to handle as the project scales but beware, making a change would mean making that same change in every animation controller.
@@SmallHedgeHQ thanks I'll give this a try. in the future if you make more animation related videos do keep fps animation setups on your list if you make more of these someday. 😃
for the idle animation, wouldn't it just be easy to set the first value of currentIdle to 1, check if it's over 7 and loop it back to 1 and just have the last else call ChangeAnimation($"Idle {currentIdle}"); ??? Just kinda feels like there's no reason to add extra steps for something relatively simple.
EDIT: And someone beat me to it a little further down like 3 weeks ago, sorry.
Yeah you’re right, would be a lot simpler. I actually corrected this in the latest video where we instead used enum arrays and hashes to play animation.
This has some drawbacks though. Consider large game with large codebase with lot of legacy code, or case when you even don't have access to some code. Then you are porting some features and in that case using animator is really convenient. Otherwise your visuals are tightly bound to code, which is not good. Or you can't give some tasks to tech / ui artists who are not that familiar with code.
It's good to know that there's way to make move between animation with out animator traction
However I prefer to use the animator traction in my game
But if it's system that I'm not able to do with the animator it may use this system for reference.
That's my sounds weird to you but i personally prefer to not make the wail animator system with code
I suppose it comes down to what your default is and how you arrive at solutions. With game development, there’s an infinite amount of ways to do the same thing. It’s just about finding the workflow which suits you best.
Thanks a lot buddy
Unity blend trees....💀
лучший, бро 💞💞💞💞💞💞
Thanks dude you saved me from hell!
Thanks you🎉
Welcome 😊
Unreal: Just use Animator.
Unity: Use animator, through code.
Stride: F*ck it, do it all through code.
lol
🎉
well...unity animator is terrible, but controlling all of your animations with code is even worse.