How to Program in Unity: State Machines Explained

preview_player
Показать описание
Learn the fundamentals of programming State Machines in Unity with this new video break down!

This tutorial explains important concepts of the State Pattern, and how to use State Machines when programming! Today we will walk through an example project to showcase the benefits of using state, the state pattern and state machines in Unity!

This is the first episode in a new series of videos on this channel: Programming for Production. In this series, we'll take relatively complex software development topics and try to break them down in easy-to-understand way. Let's take our programming skills to the next level!

SUPPORT THE CHANNEL:
iHeartGameDev Merch:

WANT MORE?
Interested in learning more about animating characters in Unity? Check out my growing series of tutorials:
✦ Like the vid? Please consider Subscribing!
✦ Missed out on the last episode?

SOCIAL:
✦ Discord
✦ Twitter

LINKS FROM THE VIDEO:
🤖 Download Jammo for YOUR game:
⭐ And Check Out @mixandjam !

GEAR:

►TIMESTAMPS:
Intro: 0:00
The Problem: 0:40
What is State: 0:57
Anything Can Have State: 1:42
What does State do: 2:04
What is the State Pattern: 2:38
Bad-Implementation Apple Pseudocode: 3:08
Making it more complex: 5:04
Why This is bad: 5:55
How do we use the state pattern to fix this: 6:51
Finite State Machine Explained: 7:18
State Machine Implementation Explained: 8:25
Implementation Example Begins: 9:48
Creating Current State and Instances: 11:17
Defining Methods: 11:50
Setting Current State and using State Methods: 13:20
Running Update within State: 14:15
Switching States: 14:59
OnCollisionEnter: 16:44
Finishing the Example State Machine: 17:03
Finished Product and Benefits: 17:27
Рекомендации по теме
Комментарии
Автор

This was amazing, omg! I'm actually walking away from a tutorial understanding! Usually I gotta like watch a few times or somethin to get it, but the code and concepts was explained well!

Also, you mentioning Class Inheritence a lot helped me actually understand that too. I've never been able to get it, but it makes a lil more sense to me now. Thanks man, this was awesome!

PopSusi
Автор

What I dig about your approach here is you actually take the time to explain the why and the theory first, as opposed to just providing code for people to copy with no understanding. Great stuff.

OptimumSlinky
Автор

I've watched nearly 10 tutorials on FSMs -- and this is the first I actually understand and can use. Thank you!

ElSonk
Автор

You know why this the BEST Tutorial ever ? Because basically there is a VISUAL storytelling + Explaining STEP by STEP as if the viewer has no knowledge + the THEORITCAL part explained with the Diagram + An Easy and Understandble EXAMPLE !
You sure have all the qualities that a teacher must have !
Good luck keep up the great work

sidahmedrekik
Автор

This is one of the best Unity programming tutorials I've ever seen. Great stuff and thank you for making this!

ahmadel-baher
Автор

Wow, that was a gamechanger. You should make a video about all design patterns like this and maybe SOLID principles too :) Anyone can understand with your ways. Thanks <3

dogukangozum
Автор

Coming from an AI background, this is really good. I think a lot of programmers gloss over things, but this was really thorough. I also like that you showed how complex numerous conditionals can be, which is a common issue in development, this will teach people to recognize when to use a State Machine.

I myself have a very complex player controller, which is only going to get more complex, and I look forward to your next tutorial.

neenaw
Автор

As an experienced C# developer, I can say this is a very thorough, clear and correct explanation, good job!
One optimization (depending on the context) would be to not retain the created state in the Manager. Instead, having each state as a Singleton will load your game faster since you will have only one version of each state to instantiate at startup. Simply call appleRottenState.Instance in the SwitchState method. It will instantiate your object when needed and keep it in memory in case there's another SwitchState called. Another choice would be to not keep them in a Singleton and simply instantiate them each time a switchState is called. It all depends on the object itself (complex or not, easy to instantiate for the machine or not) but it's worth noting and make the Manager slightly shorter.

hugogogo
Автор

I'm learning coding from YouTube (like many). I've gotten most all of the basics and had hit a roadblock as my scripts started becoming a big bag of noodles! This tutorial gave me the knowledge to solve ALL of those problems! Thank you SO much! you are an awesome teacher!

tinfoilhelmet
Автор

Never would I think that a 20-minute tutorial will give me such a useful principle for developing games! This is amazing, and I love it!

flatikk
Автор

This is the most clear, concise, and practical tutorial on state machines in Unity I have seen in the last 10 years. Thank you!

infernumex
Автор

The bad psuedo-code part of the video was fantastic. It demonstrated a use case for this system with a situation that many learning game developers have experienced at some point, all in a really clean and easy to understand way. Good shit.

DapperNurd
Автор

Thank you for this wonderful tutorial! Your explanations are very clear, but I also really appreciate how you formatted the visual aids for easy side-by-side comparison, and re-iterated concepts so that they were clear.

lakemonstergames
Автор

I really liked this video!! It's the best one of state machine I've ever seen! Congratulations!!!!

padekz
Автор

I have watched about a dozen videos on State Machines and they all go over my head. This video was clear and made sense. Thank you for making this!

lithiumjuiceartwork
Автор

I don’t know why I have never seen Pseudo code before, I’ve watched hundreds of tutorials. That simple demonstration made understanding the concepts 100x easier, I could actually see and understand what was written and why the State machine is beneficial. Great job and thank you!!

money_hyde
Автор

just the absolute exemplary game dev tutorial video, I came in not knowing much about states and with my notebook busy, have left with the ability to go integrate State Machines into my own game. Thank you so much

cleverestwoot
Автор

Best Unity tutorials by far. Your series is the new standard which will likely be used for at least a few years.

__--_--_-----
Автор

Gotta be one of the best explanation I've seen

ramizali
Автор

Dude, what a clean explanation, I can't overstate how exciting this new knowledge is.

seanrendall
welcome to shbcf.ru