Undo and Redo with the Command Pattern - C# and Unity

  Рет қаралды 23,908

One Wheel Studio

One Wheel Studio

Күн бұрын

Пікірлер: 34
@OneWheelStudio
@OneWheelStudio 4 жыл бұрын
For those who like written tutorials! Command Pattern: onewheelstudio.com/blog/2020/10/24/command-pattern-encapsulation-undo-and-redo
@JasonStorey
@JasonStorey 4 жыл бұрын
great video, clear and well explained. In general though I would personal favour a "stack" instead of a list as by design you can push and pop the commands onto the undo redo stacks and avoid having to maintain indexes etc. Also while I 100% agree on encapsulating a commandhandler/manager It is still ill advised to expose that implementation detail out of the character. If a character can undo/redo his movement it shouldn't matter how that happens, if it is delegating or not, so to avoid Law of Demeter violations I would keep the Undo/Redo calls on the Character and internally delegate them to my handler `public void Undo => commands.Undo() ` etc.
@milhouse529
@milhouse529 3 жыл бұрын
Love your style of teaching, you earned my sub, sir! You mentioned behaviour trees in the state pattern video and I'd be delighted if you made a video about that topic.
@Iboshido
@Iboshido 3 жыл бұрын
such a nice and clean tutorial
@zebgagang
@zebgagang 2 жыл бұрын
Good tutorial. I would like to mention, that I prefer to use Stack in such case. More flexible and code looks more elegant. Thx for sharing such great explanation of this pattern.
@ricniclas
@ricniclas 2 жыл бұрын
I never though about using object pooling for the commands! what an intelligent idea
@justinwhite2725
@justinwhite2725 4 жыл бұрын
I would have created a new list for redos that got cleared if you enter a new command. Undo removes a command from the list and adds it to the redo list. Redoing removes it from the redo list and puts it back into the main command list.
@THEspindoctor84
@THEspindoctor84 2 жыл бұрын
this channel is really awesome. Thanks for another great video!
@amilkarmassy
@amilkarmassy 4 жыл бұрын
thanks for sharing your knowledge! +1 sub, greetings from Bolivia
@OneWheelStudio
@OneWheelStudio 4 жыл бұрын
I'm glad it was useful!
@Renegen1
@Renegen1 2 жыл бұрын
so well explained
@OneWheelStudio
@OneWheelStudio 4 жыл бұрын
Is there another pattern you'd like to see covered? Which one?
@jaxowaraxa
@jaxowaraxa 4 жыл бұрын
Flyweight ?
@alejmc
@alejmc 4 жыл бұрын
MVVM? Has this been tackled already? It is my understanding that it would play well with Command patterns.
@abhijithnarayan5483
@abhijithnarayan5483 3 жыл бұрын
Bridge Pattern
@waynegamedev6202
@waynegamedev6202 3 жыл бұрын
Factory Pattern
@marcohuiberts1036
@marcohuiberts1036 2 жыл бұрын
I think adding the undo command to the list is better done after execute. If execute fails, and you want to run the undo, the last one failed, and the undo will fail.
@EternalStud3nt
@EternalStud3nt 3 жыл бұрын
Why doesn't this guy have more subscribers? Goldmine, thanks
@dmytroskoropadskyi5792
@dmytroskoropadskyi5792 4 жыл бұрын
Ty for your work! :)
@varan9412
@varan9412 4 жыл бұрын
thanks, great video
@ardhenismuhammadaflah7818
@ardhenismuhammadaflah7818 11 күн бұрын
great video for explanation! i solved my solution after 5 minute watch your video!
@richardrothkugel8131
@richardrothkugel8131 Жыл бұрын
I've watched the observer pattern video dozens of times and have fully integrated the pattern into my own project. Although I understand not wanting to deviate from a 'pure' command pattern, I think it would be far more useful to show the command pattern together with the observer pattern. I won't have any trouble converting it over when I'm implementing it myself, but people new to observer might have trouble. Perhaps you could make a new video, something along the lines of 'Integrating observer and command patterns', which could cover this topic.
@OneWheelStudio
@OneWheelStudio Жыл бұрын
I wouldn't worry to much about deviating from a pattern. I see them as a framework to be modified for the current situation. In terms of integrating the observer pattern, in my mind that would look something like invoking an event when a command is executed or maybe when it's undone. That might be a static event that anyone can listen to or it might be a "callback" that gets passed in along with the command. This would let the object that created the command know when it was executed.
@spiralhero9260
@spiralhero9260 6 ай бұрын
What I can't quite understand is how all this abstraction actually helps with the logic? Can't you just have the list of commands directly in the code instead? Why do I need a middleman?
@JulesCalella
@JulesCalella 3 жыл бұрын
I can see this being used in tutorials for any game, where you want to progress through particular moves and allow the player to go back to a previous step. Would this be overkill for that or is this exactly what you'd use?
@OneWheelStudio
@OneWheelStudio 3 жыл бұрын
I’m not sure exactly what the tutorial or game looks like so a bit hard to say. My gut says it might be overkill, but depending on the game it might be perfect. I wonder if it could be used beyond a tutorial too? Can it be used for a similar mechanic in the game?
@MrZero000cool
@MrZero000cool 4 жыл бұрын
Hey, thank you for your tutorials. Do you think it would be possible to make a tutorial on aligning an moving object with uneven terrain, especially its rotation? For example if my cube goes up a slope it should rotate to match the slope angle. Its the rotation part to align it with the terrain that I don´t understand how to do in bolt. That would be such a great help and there are no other bolt tutorials that tackle that topic.
@OneWheelStudio
@OneWheelStudio 4 жыл бұрын
I probably won’t be able to make a tutorial that is that specific, but the first thing I would try is to raycast from the object to the terrain. I *think* you can then get the normal (vector perpendicular) to the point you hit on the terrain. From there you may be able to align your object with that vector?
@MrZero000cool
@MrZero000cool 4 жыл бұрын
@@OneWheelStudio Thanks a lot for the answer. That was exactly my approach to get the terrain normal via raycast hit normal and then set the transform.up of the object, but it always resets the rotation of the object. It has something to do that transform.up uses local scale instead of world scale and as a beginner that´s where I get problems, so I was hoping that you maybe can help, but if its too specific I´ll just continue my google search for solutions. :) thanks again for taking the time to answer
@BunnyHuggerr
@BunnyHuggerr 4 жыл бұрын
Im still cant understand the difference between this one to memento undo redo
@muhammetuymaz2961
@muhammetuymaz2961 3 жыл бұрын
I guess, we can use two stacks for undo and redo
@MohitBanke-d9m
@MohitBanke-d9m Жыл бұрын
pks make more design pattern tutorials.
@OneWheelStudio
@OneWheelStudio Жыл бұрын
No promises, but any pattern in particular?
(Better) Object Pooling - I Didn't Like My Old Solution
8:49
One Wheel Studio
Рет қаралды 15 М.
What You Need To Know About The COMMAND PATTERN
14:09
BMo
Рет қаралды 3,6 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
When to use Factory and Abstract Factory Programming Patterns
12:13
Delegates, Events, Actions and Funcs - The Observer Pattern (Unity & C#)
11:48
The State Pattern (C# and Unity) - Finite State Machine
10:04
One Wheel Studio
Рет қаралды 69 М.
Generics in C# and Unity - Do More with Less Code
12:40
One Wheel Studio
Рет қаралды 13 М.
How to Program in Unity: Command Pattern Explained
22:37
iHeartGameDev
Рет қаралды 71 М.
How to Program in Unity: Observer Pattern Explained
15:57
iHeartGameDev
Рет қаралды 118 М.
Change Behaviors with the Strategy Pattern - Unity and C#
8:07
One Wheel Studio
Рет қаралды 41 М.
Command Pattern - Design Patterns
14:49
Web Dev Simplified
Рет қаралды 101 М.