How to Program in Unity: Command Pattern Explained

preview_player
Показать описание
Learn the fundamentals of the Command Pattern in this new video break down! We'll explain how to use each component of the pattern using c# programming in unity!

This tutorial explains important concepts behind the Command pattern and how to use 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 a new episode in a growing series on this channel: Programming for Production. In this series, we take relatively complex software development topics and try to explain them in easy-to-understand ways. 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 @Mix and Jam !

GEAR:

►TIMESTAMPS:
Intro: 0:00
Classes Deep Dive: 0:45
The Focus of Today: 1:30
Program LifeCyle: 1:45
The Question of the Day: 2:10
The Command Pattern Definition: 2:50
Classes Explained: 3:08
The Concept of the Command Pattern: 3:40
The Structure of the Command Pattern: 4:10
Meta Example: 5:34
CODE STARTS HERE: 6:30
Project Without Command Pattern Overview: 6:40
Refactoring with the Command Pattern: 7:18
Abstract Command Explained: 7:46
Concrete Command Explained: 10:00
Using just the Concrete and Abstract: 11:40
Invoker Explained: 12:12
Important point about the Command Pattern: 13:28
Lightswitch Invoker: 13:58
Decoupling: 15:00
TurnOff Refactor: 15:18
What this Invoker is missing: 16:27
Phillips Hue Example Setup: 16:47
A Better Invoker - LightApp Invoker: 17:22
Undo Functionality: 19:18
Whats might come next: 21:50
Рекомендации по теме
Комментарии
Автор

I loved that 'like' example. I was fiddling with some lego, which I had to snap together and put down before moving to the mouse to like the video. Perfectly executed!

Tarodev
Автор

Over a month of research, recording and editing later... I can’t wait to finally share this tutorial! See you all Sunday! Cheers! 🍻

iHeartGameDev
Автор

This is actually the most useful style of editing a video about programming. easier to understand than listening to a professor talk for an hour with a piece of chalk.

daffertube
Автор

Hey! I just wanted to say that your tutorials are the most clear and detailed one that we can find on YouTube. It may not seem like it but I know that editing this kind of video takes a lot of time. Also, these topics (Design Pattern) are so important in game development. It allows us to complete a game without any frustration. Big congrats and thank you!

anthonytrepanier
Автор

One thing i have to say is, i have seen lots of tutorials of unity and programming about many topics, and there are lots, but all of them are not that much relevant some are and one of them is yours one thing that i love about you and your channel is, your only talks about relevant things means point to point no other useless stuff and this makes your video more interesting. that's why i love your channel. keep uploading this cool stuffs. love you from india...

HarshYadav
Автор

I watched a lot of tutorials to be able to understand everything about the command pattern and adapt it to my needs; your tutorial has the clearest explanation. (I still suggest watching other tutorials too if anyone is having problems)

marularch
Автор

Despite the difficulty of me trying to grasp this concept, your explanation is rock solid! I feel that if I watch this once or twice more, I'll actually be able to implement this in my games!

Mgtn
Автор

I clicked this video out of interest since I've learnt design patterns and have been programming for a while but have only recently heard of this pattern. I ended up realising that despite not knowing this pattern, I've already used it in a personal project for the purposes of compilation of a scripting language I created for a text based action game engine I made back in University. At least now I have a name for this pattern.

This just shows how useful this pattern is that despite not knowing of its existence, I ended up using it because it achieved the goal in a clean and efficient way.

Damnesia
Автор

I love how you take things from ground up and then build upon that. One of the best videos of command pattern I have ever watched!! ❤❤
Please make more videos of this type.

radiantgames
Автор

Please also cover SOLID principles exactly like the way you did state pattern. And obviously this video was helpful like always :)

zeeshansattar
Автор

Great video!! just a small correction. At 13:44 STACK is LIFO (Last in - First Out).

Love your videos!!!

lucasafonsolombardimoreira
Автор

very good and detailed explanation of everything, from basic to advanced for programmers of all level to understand

longNguyen-higy
Автор

I love your tutorials and explanations :) Especially for this advanced stuff. You're helping me a lot. Thank you for those videos!

alexmilanu
Автор

Excellent. I can't say I've ever seen a more complex group of programming topics condensed so clearly in 22 minutes. Excellent concept breakdown, excellent presentation, excellent explanations. For those of you who are somewhat new to programming and struggle to understand concepts like interfaces, abstract classes, or their purposes, watch this video. It will make it clearer. If you already understand these things pretty well, you'll wonder why nobody ever explained it this way to begin with.

bitgalaxis
Автор

A better design is to create a CommandProcessor class with a Queue<ICommand> collection that stores commands and processes them. Stack<ICommand> stores the history. But for anything other than trivial commands that finish instantly, you have a lot of challenges to overcome to have accurate undo-ing of commands. The CommandProcessor can be added to any class you want to execute commands, and will be nice and generic so it doesn't care what type of concrete commands it's running. It only cares if it's a simple ICommand or an IUpdatedCommand that needs updates and takes a while to finish. Without this, you can't implement more interesting things like moving a character along 5 waypoints because all of the commands execute instantly and the character will just go straight to the last waypoint instead of following them in sequence and moving on when the active one is complete. It was kind of a challenge for me to implement this sort of system properly, but once I ironed out all of the problems in it I ended up with a reusable system I can apply to literally anything and just create new commands for it to run literally any logic.

Some things may to inherit CommandProcessor and override the way it processes commands, so mark its methods virtual. An example is if you're making an RTS game and you want a unit to attack an enemy but if it's given a an order to move or retreat it will cancel the attack command and do as the player commands. Otherwise, it will be stuck attacking until it dies or kills the enemy before it can respond to the next commands enqueued, and it can't do that if it's dead, can it? So the command processor for the units will override the ProcessCommands() method of the CommandProcessor base class and deal with this accordingly, by canceling commands that are followed by a higher priority one like an immediate move, stop, retreat, etc ...

GameDevNerd
Автор

Hey, solid intro on command pattern; thank you for that. One tiny nitpick (mostly for those watching to think about) at 17:05, SetRandomLightColor() should really just pick a random color, then call SetLightColor() feeding in the random color instead of repeating the same logic.

DylanBurke
Автор

This is the next level of tutorials. Not only explained in the "command pattern for dummies" kinda way, but it's also animated, well-structured, and super concise.

zaprodaju
Автор

I really liked the analogy with the like this video command, smart!

BoryslavMalishevskyi-jx
Автор

i watched tons of tutorial videos and you are one of the best. Really appreciate your effort of making animations and stuff to make it really easy to understand.

kizz
Автор

Bro you should make a series of coding it is really difficult and your way of explaining is owesome

babarrehman