Animate like a Programmer
As a programmer, using the Unity animator can feel like you're losing some control over your game. We can manage our animation transitions entirely from code... Animation will feel as natural as your player controller script.
Code: bit.ly/3P4DdA2
I'll be expanding this code on my ultimate 2D controller, which can be found here: / tarodev
Animancer: assetstore.unity.com/packages...
❤️ Become a Tarobro on Patreon: / tarodev
=========
🔔 SUBSCRIBE: bit.ly/3eqG1Z6
🗨️ DISCORD: / discord
✅ MORE TUTORIALS: / tarodev
Пікірлер: 700
I wasn't convinced until I saw I could bypass trying to line up the animator arrows in the grid
@ShinichiKudoQatnip
Жыл бұрын
Exactly!
@blameyourm8519
Жыл бұрын
hahaha
@11sveden12
Жыл бұрын
I'm comforted knowing I'm not the only one driven crazy by this. I also spend way more time in Shader Graph lining up nodes than I do making actual shaders...
@LeeTwentyThree
Жыл бұрын
this saves me soooooo muuuuuuuchhhh tiiiime i love this video
@mariyamrifa406
11 ай бұрын
@@blameyourm8519😊p . ;blue🔵 h😊) gF/+0=°Phl de₹
As a programmer learning game making in Unity I really like this. Now, if only there was a "How to create art/animations as a programmer"
@Tarodev
Жыл бұрын
Oh mate... If you find it, let me know
@neintonine
Жыл бұрын
You can add StateMaschineBehaviours to your Animator states. That way you can programmatically create animations. It is a bit finiky tho. f.E. the duration of the animation is set by the animation set in the state. There is a default duration you can just repeat or you just add a empty animation with your desired duration or you just use your animation and use it to spice up that animation. Plus there is no transitioning, what makes the creation of good animations hard. Transforms, you want to change, must not have any data in the animation you set. In general I would use this feature for simple animations like idle bobing or for stuff that has the same start and end point like firing a weapon. I personally believe it wasn't really designed for that. Sadly I haven't found a good package, that adds new features for such an use-case.
@progress_games
Жыл бұрын
Program a bot to scrape assess from pre existing games
@kazukixe
Жыл бұрын
Asset store?
@jasondads9509
Жыл бұрын
Dalle 2?
I love how this video is under 2 minutes. Quick and straight to the point. Personally, I prefer the tree and have spent a great amount of time mastering it, but for quick prototypes and game jams this would be WAY faster to set up compared to messing with the tree.
@Tarodev
Жыл бұрын
Glad you enjoyed the short form content brother 🙏
@Glooberloob
Жыл бұрын
What do you prefer about the graph/tree? I've only made a couple small projects in Unity, but this approach seems much more convenient to me. Would it be a problem with scale?
@KeybiKeyboard
Жыл бұрын
@@Glooberloob The strength of the graph/tree I believe would be helpful for 3D games such as combo-ing and whatnot. Also, the Finite State Machine Behavior can be more easily used in conjunction with the graph/tree (I think, correct me if I'm wrong but I find it easier to fix there especially with AI)
More tutorials need to be like this, immediately explaining what you want to show off without fluff. Amazing vid
I've only found your channel yesterday but already you are in my top 5, short and to the point. Keep up the good work!
@Tarodev
Жыл бұрын
Aiming for that #1 spot
@spicyshotz
Жыл бұрын
@@Tarodev Im sure you'll get there in no time 😉
@leukk_
Жыл бұрын
@@Tarodev You'll get there for sure, i love the fact that you cover "intermediate" / "advanced" topics as well that don't necessarily bring you as many views but are much more useful than having 1000 + 1 character controller tutorials
@natickgames1821
Жыл бұрын
Come hang out in his discord!
@GameDeveloperTR
10 ай бұрын
Which channels are currently in the top 5?
I am working on animations literally this second. God sent you
I always appreciate seeing new approaches to the same repetitive things I've been doing all the time. Thanks mate🐦
Thank you so much for posting videos for intermediate level coding, it’s just what I need!
I really love your videos man, short and to the point. I’m a little confused on 3D animation but honestly the more I think about how to implement it the more I think I can
@Tarodev
Жыл бұрын
If anything 3D animation is a bit easier as you can interpolate frames between two animations (this is handled automatically) to create smooth transitions. You can do it brother!
This is sooo handy! Definitely going to play around with this. Thank you!
This is so interesting. I would seriously love to learn more about how to implement this. It seems so clean and efficient. Every 2D tutorial I’ve seen just talks about the regular ‘spiderweb’ way.
@SolChaos-ph7ye
4 ай бұрын
You seriously limit yourself if you animate this way. However, you shouldn't have spiderwebs in the animation graphs either. Once you learn the animation graphs system you will have clean clear animation states using layers, substates, and blend trees. the spiderweb only comes from lack of experience. animating in code as shown in this video is not recommended.
@andrueanderson8637
Ай бұрын
“Clean”? This literally leads to ridiculous repetition and duplication in your code. It’s the opposite of clean.
had to come back with a new channel because the game i was working on last year uses your character controller... thank you for existing btw! hope you're overcoming any stress you're dealing with at this current point in time and that this year goes great for you :)
This Channels like finding a hidden gem, informative and quick to the point. Nice content
So much information condensed into a video that's under 2 minutes. Beautiful Taro! And now it feel like a ton of my videos should be refactored to use this method of animating XD
@pedrinkss
Жыл бұрын
Combining this with the state machine that you showed us = gold!
@glassmarble996
Жыл бұрын
maybe you make a video about this.would be good.
Yo, that was extremely helpful, I saw a video from lost relic games talking about the concept of coding animations, but you took it to the next level
Thank you! I didn't know about this feature! I already have a state machine in code to manage transitions and trying to match the Unity animator with it was painful. This just works with basically one line of code! I think about this video almost daily and feel thankful for it :)
Simple, objective and precise. Thank you Tarodev!
I really love your videos, they always have interesting topics actually.
+1 for Animancer Pro, it makes working with animations programmatically so much easier. And, even solves some awful blendtree glitchiness by letting you disable foot IK on a per-animation basis. Technically, another option is directly implementing the somewhat abandoned Playables API which Animancer uses behind the scenes.
This tip is so simple yet so effective. It just pulled me out of a full half-day unity animator nightmare. Thanks Tarodev 💙
Have been programming in Unity for over 6 years and always wrote my own animation system to avoid the issues addressed in this video. I never heard of CrossFade, this would have solved everything I solved writing my own systems while keeping it connected to the tools Unity Provided. Thank you for showing this! To return the favor, let me address the following thing I noticed about the video: About the animation states. I categorize finite state machines into 3 categories: Level 1: Tracking state by multiple booleans Level 2: Tracking state by an enum Level 3: Tracking state / having the logics of states in separate classes. You were using a Level 1 Finite State Machine. I highly recommend going for a Level 2 or Level 3 Finite State Machine. The nice thing about having it in separate classes is that you can do simple things such as: * WalkingStateClass (holds logics of walking) * FreezeStateClass (changes color when entered, and back when exited) And to have the player freeze when hit by an object, you only have to: CurrentState.Exit(); CurrentState = new FreezeStateClass(); CurrentState.Enter(); Because WalkingStateClass is no longer CurrentState, it no longer is being updated so no walking logics is available anymore. Keeping your behaviour simple and preventing complicated bugs.
@Tarodev
Жыл бұрын
Very interesting. Thanks for the write up 🙏
This is absolutely fantastic, thank you so much! I love doing things through scripting, it just makes so much more sense in my head, and I feel like I have so much more control over how I do things. Never going back to spaghetti trees lol.
This is super useful! More of this please :)
I work as a software developer and I'm just starting to get into game development in my free time. This was perfect for me as I prefer to use code over Unity tools if it makes the process simpler, which this really does. Thank you!
Wow, that looks a lot easier to follow than the spider-webs with parameters that you can't tell apart. I'll also have to look into that string hash thing you used; never heard of that one.
this is absolutely awesome did not know about this, thanks !
I love your videos, you just get the point so efficiently. thanks.
Really like this idea tbh. In the past years, for a few of my games were animation transitions aren't that relevant, I always just made a state machine that is used in the MonoBehaviour and just play and adjust animation state in the logical states, kinda like you showed in the video. It prevents a lot of the pains of having to deal with the Animator and having to maintain 2 different state machines. More recently I also worked on a small editor script that basically generates the hashes of the animator state names and parameters as static variables into a file, that's pretty useful as well ^^
Im getting into unity with some friends. Im a professional programmer but this is my first real foray into game dev. My friends are all artists so I handle all the code. This channel is everything I want. I can figure out how to do nearly everything from the docs but never really know if Im following good practice. Most tutorials have been worthless because theyre not written for or by programmers. Loving you channel because its exactly what Ive been looking for
@Tarodev
10 ай бұрын
I'm here for you 🙏 enjoy your journey
What an amazing video, this is so much better than trying to fiddle with the unity ui
This is marvelous
@Tarodev
Жыл бұрын
Good luck brother! Remember, the provided script is still basic. You can deck it out with some advanced features like OnFinish and OnStart events
@NickMaltbie
Жыл бұрын
@@Tarodev I have a state machine based character controller so I already have all the transitions mapped out! Thinking of switching it to coyote based state machines so I can decorate the states with attributes on what animation to switch to when loaded!
thank you so much for sharing this. it seems like a much easier way to animate considering i always just set up animation triggers and call them one by one. and great presentation too!
@Tarodev
Жыл бұрын
Enjoy your new power
Always love your stuff. Best unity tut tuber
@Tarodev
Жыл бұрын
Thanks Caleb 😘
Great video! I'm glad to see more devs promoting this approach. The mechanim is a clunky and unessessary system (for coders).
@Tarodev
Жыл бұрын
You know, I've watched most of your videos, but somehow missed the one on this topic. Another commenter mentioned they originally learned it from you, so I went and watched it swiftly 😂 Love your stuff man!
I switched to code-driven animation almost from day 1 of learning Unity after seeing LRG's tutorial on how to avoid Mekanim spiderweb madness. I barely even know how to use the Unity animator at this point. Your string hash to int trick is something I have not been doing though, until now! Thanks!
@gamedevteacher7065
Жыл бұрын
Got a link to that video?
@synchaoz
Жыл бұрын
@@gamedevteacher7065 kzread.info/dash/bejne/oHafy7WDZd2TmKg.html&ab_channel=LostRelicGames Simple little string based animator state machine. I've extended it a bit for personal use and even implemented parts of yours, but John's does a fine job even just out-of-the-box
Good job making this video, I feel the YT algorithm read me my mind and showed me this when I needed it.
"I read every single one of them." WELL THEN, I HAVE SOMETHING TO SAY TO YOU. that's a very well done video and I appreciate the time and effort that it must have taken to make it.
@Tarodev
Жыл бұрын
Oh... Well thank you sir
Good stuff, I use a very similar system for a 2.5D platformer project, the level of control is very good to have, and no animation/transition setup overhead.
This is so helpful. As someone coming to Unity from GameMaker Studio, this is really similar to how animation is done there. So much easier for sprite work!
@Tarodev
Жыл бұрын
I wasn't aware of that, interesting
Good stuff! My current game is a track- based music game so all of my character animating is being done on the timeline for this one, but I'll definitely keep this in my bag of tricks for future projects. The more you can calculate programatically, the better!
@Tarodev
Жыл бұрын
This strategy seems ideal for that type of game, so long as you have events being fired for the beats
@ProdigiaGames
Жыл бұрын
@@Tarodev Actually, that makes sense. I was just going to make manually animated segments with timeline triggers to branch/loop, but that could potentially help automate at least some of the animation setup. I'll have to weigh my options!
thank you! This reminded me of a tutorial i watched last summer from Kiwicoder but in 3D. Programming animations this way seems the cleanest way.
You can take this a step further by using Scriptable Objects to create states and then having a State Machine Monobehaviour. This way you can link up states to different animations which is particularly handy for games with multiple playable characters and generally works better as a more modular methodology than the firewall
@Tarodev
Жыл бұрын
I actually love that!
You had me at OCD, really enjoying your vids man keep it up PLEASE. Learning lots even started making my own space shooter!
@Tarodev
Жыл бұрын
Hell yeah brother!! Good luck with the shooter
This is amazing! Getting rid of transitions and blend trees is a god send. I work exclusively with pixel art games and this is a perfect solution to the spider web woes I continue to deal with. This method is simple and intuitive. As a newb to game dev, a more detailed video doing a deep dive into creating the script and going through some different interactions of the code with various actions like attacking, jumping, et cetera, would be great. Thanks for the code and the quick video on how it all works.
@Tarodev
Жыл бұрын
I'd love to hear how you go with it. Reply here when you've had a play 😊 I have a pretty fleshed out version on my patreon if you're ever interested
Amazing idea. Animated transitions have not been relevant for some of my games over the past few years. I just created a state machine for the MonoBehaviour and just played and adjusted the animation state in the logic state like you showed in the video. It avoids many of the problems of dealing with animators and having to maintain two different state machines.
Mr Taro, that is fantastic video! Thank you so much for it :D. I had no idea this method exists!
@Tarodev
Жыл бұрын
Thanks buddy :)
It's like you were sitting across the "office" from me today! I've been struggling the past week with this exact scenario but 3D. Thank you so much sir.
@Tarodev
Жыл бұрын
Here to help 😉
I'm relieved that I'm not alone to align horizontally the animator connection lines :D
What an effective, quick video. Humour, bit size and taught well.
@Tarodev
Жыл бұрын
Thanks Eli
Didn't expect that 2 minutes video could be so useful.. You are genius, thanks!🙂
Thank you. I converting the state to hash looks like a good idea and it could be used for an enum. Can't wait to test it out.
@Tarodev
Жыл бұрын
Just ensure you're still sending the hash to the animator as it's significantly more efficient
I highly recommend using Playables graphs for 3d animation. It's built into unity (but with little documentation) and offers even more programmer centric design. For instance, you can use animation clips as serialized fields and reuse animation graphs just like you reuse code. There is extra work needed to get it set up but it gives you so much more control. It also let's you customize transitions so they're not linear!
@mufelo
Жыл бұрын
Animancer takes away most of the extra work and uses playables in the backend.
this channel is a blessing ..honestly. superb content.
@Tarodev
11 ай бұрын
Thank you ❤️
I'd like to understand ANYTHING you just said. Well done mate.
this looks a lot easier than working with unity animator, it would be great to see a full tutorial on this!
@Conor_Tuohy
Жыл бұрын
Yes - an explanation of your full code, and what connects to what components, what terms or commands actually do, why you use the techniques and code you use, etc - that'd be very useful to us folk just starting out!
Crossfade is new to me, this seems right up my alley. Great video man 👊👊
This was really helpful, I'm just not a big fan of the unity animator, and my brain works very logically, so I will be using this method a lot more, thanks so much!
Oh man! Thank you so much... I love this!
Hey TaroDev! Great video, honestly struggled with animations and the damn spider webs way too much. Actually checked you out after the blackthornprod 3d game dev video, you were a complete machine in that! Thanks for the video mate, have a good one!
@Tarodev
Жыл бұрын
Welcome aboard mate 😊 I've had a bunch of complaints that I threw out too many previous dev implementation in that video, lol. Woops.
@viramyar4259
Жыл бұрын
@@Tarodev all good mate, p.s I liked your changes
LockState is probably what I needed. I followed LostRelics version of this in a lil endless runner I made and I noticed animations being overridden. So in the animator I linked necessary ones back to idle, also turning off the autoloop, and then in my if statement checking player states, I stop/prevent the state changing unless it's not one of those animation states. E.g. player is landing from a jump, even if they are grounded, I don't want idle to play since I want the jump animation to finish, if not jumping play idle but when jump is finished in the animator it will go back to idle. Your LockState example essentially does what I wanted 👌 Also I wish beginners knew of this because Unitys spider web is a nightmare and I can't see an advantage over just coding it.
I just know this API after a few years working with unity, thank you this is looks awesome.
Great video Taro! Never heard of CrossFade or the firewall pattern before this, definitely have to try them out
@Tarodev
Жыл бұрын
You've never heard of the firewall pattern as I coined it while writing the script :D
@JamesMakesGamesYT
Жыл бұрын
@@Tarodev Well now I don't feel too out of the loop :D
@gogokowai
Жыл бұрын
The standard name for the "firewall pattern" is "guard clauses". It normally refers to returning after checking function parameters for valid values, but can also refer to a string of conditionals and return statements. Firewall pattern sounds cooler, but it might be a confusing term if you're writing network code.
Keep the good vids, amazing!
Incredible content!!! Feel like a beginner watching your videos!!! Grow that channel!! Grow like crazy!!!
@Tarodev
Жыл бұрын
I'm tryyyyyyiiiinnnnngggg 😂
This was helpful and motivating, thanks.
I always had so much trouble with animator in unity. This video is great!
Brilliant stuff
I've been looking for something like this!
This is so helpful!!
Amazing work, bro !
This is sooo useful, thank you sir
Brilliant!
Omg this is everything I ever needed as a programmer. Thank you
@Tarodev
Жыл бұрын
Enjoooooy
😭 the line… you just touched my heart. That line drove me insane for so long. I hate it.
Great job as always! by the way thanks to you that you made me understand i have OCD
Another great video! Can we have your take on creating an inventory system? I know this has been done many times before but I love how simple you make complex topics and I'm sure you'll do a fantastic job with inventory. Covering things such as; Setting up the inventory, drag and drop functions on it, reactive UI based on what you have picked up / dropped and maybe some extras such as combining items from that inventory (for example, crafting.) Because these things are used in many games.
That's an easy sub for sure. Gonna try this sometime soon
Bookmarking this for the future as i think ill never use the built in animator window ever again
ooh, nice man. Thanks for that. I both hate and love unitys animation tools. But this will help me a bunch!
excellent vid!
Appreciate it!
Thank you so much!
Your channel is pure gold.
@Tarodev
Жыл бұрын
Thank you :)
Probably outside of the scope of a quick vid like this, but if you're using a state machine pattern within your own code, changing animations like this can easily be handled more elegantly than a block of if statements, ESPECIALLY if your animation is tied to state. Just have some sort of "onStateEnter" function on your states where you set your animation.
@Tarodev
Жыл бұрын
I use state machines all the time, but I like my current approach more. Way (way) less boilerplate, exact same result.
Thank you man 🖤
The shear anount of happyness, anger, gratitude and shock i feel after learning this is astounding, im subscribing for my foolishness
Yoooo 🤯 this is literally exactly what I need after just deciding today to make my platformer 2.5D with models instead of 2D with the same models baked as sprites. Nice 🤝🏾
@Tarodev
Жыл бұрын
I love 2.5D. Good luck with your project!
@lamarhoward8478
Жыл бұрын
@@Tarodev Thanks, good luck with your projects as well 👍🏾
wow thought this is a tool or something like that, but the animator itself has it. how did I not see this for all these years :D
this is super helpful thanks 🙏
Gold. Absolute gold.
I gotta test this one
dude that perfect thank you!
Amazing!
@Tarodev
Жыл бұрын
u r
you are a fooking legend!
That's nice. Thanks!
@Vanawy
Жыл бұрын
Here we go again, actually implementing it rn :D
Woah! That's really handy. Now to learn unity.
@Tarodev
Жыл бұрын
Hah! 7 days ago... did you start learning? 😂
I know nothing about animation or programming. 10/10 video very helpful!
@Tarodev
Жыл бұрын
Thanks Captain!
Wowwww i wanted to know this before, really thank you
I thought this was an asset you made and wanted to show off but no, this is straight up base unity functions. How has this evaded me for so long?!?!
@Tarodev
Жыл бұрын
It evaded many of us... But we now have the power.
@the3rdr0b0t
Жыл бұрын
@@Tarodev I will follow you to the ends of the earth, finder of ancient treasures
very nice and looks interesting