Hey everyone, hope you find this video helpful in understanding Separation of Concerns with the MVC or MVP patterns. Code links are in the description. Let me know if you have more questions and if we need a 3rd episode on this topic!
First thing, great video! I have been working as an Android Developer for 7 years now, implementing MVC, MVP and then MVVM in all my projects. One note about the video, It is not best practice to tightly couple the Controller to the view, as then you lose what you wanted, which is separation of concerns. In order to achieve that, you could use the Observer pattern and remove the dependency of the view from the controller. This is desirable because it makes the code more testable, and you get the extra benefit that if you are going to make changes to your view, no changes are needed to your controller as it is truly separated. I love your videos. I started my long-standing dream of game development and have been glued to all your videos since. Keep up the great work! 👍
This is hands down the best gamedev/unity channel I've ever seen. Straight to the point, good practices, your own game examples for clips, nice explanations with graphics/diagrams, great voice with nice pacing, no BS memes/clickbait, no selfy video on the corner blocking views. Relatively short, but concise, no fluff. Excellent, excellent teacher.
Great explanation and contextualization, as always. MVC, MVP, and MVVM are staples of proper UI architecture in video games. I'm glad that someone is finally taking the time to show people an actual implementation of one of them.
Your videos work for me as glue. Making all that I have learned come together. Now I have a new perspective and that's a big help, more than I could ask. Thank you very much.
I didn't know about UI because I wasn't interested in it, but after watching this video, I realized for the first time that there was such deep content. Kudos to you!!!!
Thank you for this super-useful video! Every time I see an update on your channel, I immediately know that there's a new video worth watching. Please keep up the good work!
you're the greatest man, I needed this so much! I've been doing this all the time in my past years on web development, it didn't occur to me to try something similar for game development, this is great, thanks
Incredibly well done. The way you showed the diagram first, explained it, then jumped back and forth between code and diagram to show which part was being implemented was really helpful. Just found your channel, looking forward to checking out the rest of your content. Keep up the great work!
Loved the Unity Game Architecture series! Suggesting a playlist reorder for better flow: Start with 'SIMPLE Tip,' then 'Improve Your Unity Code with MVC/MVP,' and end with 'Learn Unit Testing.' Amazing work and best wishes!
It is rare to have unity tutorials that go this deep. But this is exactly what I need to get to the next level! Thanks alot! I just feel like having the videos in a series might be a good idea? When I watch this video there are some things I missed and having a structure/order in which to go through the videos would be great! Even if the reality is to watch all of them, episode number for example would indicate it well. But I understand the title has other needs as well...
Thanks for the comment! Unfortunately having an episode number on RUclips is a bit problematic because new viewers don't want to jump in if they feel like they need to commit to watching a bunch of earlier content, which makes it really hard to grow the channel. While I try to make every video stand on its own, if I reference something from an earlier video - like the Event Bus - I try to include a card in the video with the link. If you really want to watch it all, start with the Patterns playlist and then the Architecture one after that. These playlists are in the order the videos were made.
This is something I've heard for quite a while and seen a bit of it but never understand what it really is and how to really implement it, thank you for this video to make me understand a bit of it, might need to watch it couple times so i can really grasp the true idea, but as always a great video from Adam.. keep it up man, i know u will be big 😄
Another great video, I need to implement it to get my head around it though. I'd be interested to see you go through a set of tutorials where you build out a game using the patterns, like a vertical slice of a game using the patterns. Would be a huge amount of work though I'd expect, and I would assume you already have plenty on your plate :D. Could be a paid course, I'd definitely pay for it.
@@git-amendI imagine it would be a lot of work to setup. Either way I've learnt a ton from your videos , and look forward to every new one that comes out
I hopr some people can learn from my mistake: I used the Event-Bus inside a system, which lead to a confjsing structure inside a mvp system. I learned that the Event-Bus is very nice for communicating between different mvp systems. Inside a system I used then simple public Actions on my view that forwards the events to the presenter and the presenter decodes what to do. I dont know if this is the best approach, but it worked pretty well for me.
Another question: Would it be a good idea to have multiple views? (E. .g with 3 different interfaces) Currently I solve this by using 1 view that contains other "views" woth SerializeField.
Through out the years I have been bitching to my fellow software developer friends on how shitty every youtuber is when it comes to programming in unity. (from the perspective of a programmer) I will like to thank you for spending time figuring out how to utilize great patterns and concept from the world of programming inside unity. Working as professional software developer I know and work with a lot the patterns you show. But I never really have the time to figure out how use it probably in unity. Thank you for saving us time on "inventing the wheel" Keep up the good work!
Great content as always, said it before, but it is so great to have these intermediate videos in sea of for-beginner stuff! One question - in a game like Dragon age, where player can switch between different characters, would you have the MVC/MVP combo for each of the characters, or would you have just one and build the switching logic inside? Having it for each of the characters makes more sense for me, but id like to know your perspecitve :) Thanks!
Thanks! That's an interesting question. I think for a Dragon Age style I can see how having one for each character would make sense. Just be careful of any state that needs to be shared between them and take that into account somehow if necessary in case you have any data they all need access to or if they need to communicate with each other.
@@git-amend I certainly dont, and I have studied them some, but a lot of studios hiring seem to love to post them in the requirements for positions. In any case, I guess I hope you can get around to it, but its fine if not :)
I've always found the terminology around MCV to be rather unintuitive, but if I understand correctly, it's basically just saying to keep your Logic, Data, and Visuals all separate from each other.
Coming from Java Enterprise development, it's nice to see examples of how to implement those patterns in Unity. Great work! ⚔⚔⚔⚔ Where would you trigger SFX cues? Would you build an observer that listens to the Event Bus or inside the view?
Thanks! My first thought was just to say, yeah I'd have a separate observer on the Bus. However, maybe not for all sfx. If it was UI sfx, that really is part of the View I would think, like mouse click sounds etc, and doesn't have to be played in 3D space either. And, potentially you could also have sfx be played directly by the ability command with AudioSource.PlayClipAtPoint which creates an audio source at any point in the world. I guess in the end, it really depends... but I think for most, I would raise an event onto the bus and let another system handle it.
@git-amend There is a rogue if statement in the posting of the ability mvc system. In the gist line 145. The if statement doesn't belong to anything (not in a method) and throws an error. Also, AbilityCommand is not defined. Will post this in discord too.
Thanks, and great question. One day I'll make a longer video about building a custom player controller like this. Basically, under the top most game object I have two children - one branch for the model and another branch for camera items. In the camera branch there is a 'camera target' game object which the camera aims at. So if something in the model branch moves, nothing in the camera branch moves, but the entire player moves them all. So essentially I'm achieving this by separating the model from the camera, but they both have the same parent.
Great video! What are your thoughts on topics like "MVC is not used in games", adds to overhead, relies on data-binding... I really like this pattern and you explained it really good! But can't avoid feeling like maybe this isn't the best pattern for game dev? Do you know what companies architectural pattern usually uses? (avoiding custom architectures, obviously). Would appreciate a brief explanation. Continue doing videos like that, really good job!
Hey Adam, i have a question and maybe an idea, so whenever i want to create a new feature often i don't really know how many modules I'm gonna need and how deep it's going to be, so do you have tips on planning it like your flow chart.. thanks in advance
What I would do is start with a skeleton UML diagram so you can see it visually. A tool like excalidraw.com/ is very useful. Draw out your first draft and draw lines where you see dependencies - make sure none of them form a loop! Once you being coding, don't be afraid to refactor. Then go back to your diagram and update it, so you make sure it still makes sense to you. Just practice and never stop learning new things, and you'll get better and better at it. Your best tool is going to be experience and knowledge. Have a read through the object and class diagrams sections of this page: www.c-sharpcorner.com/UploadFile/nipuntomar/uml-diagrams-part-1/
Great stuff, thanks! The past two videos made me wonder a couple things: * What sort of gameplay stuff would you still do on MonoBehaviours? Do you delegate collision events and Transform-changes to non-Monobehaviours, too? (As with the Update(deltaTime) function.) * I can see dependencies being injected in the non-MonoBehaviours, but would you still use the editor to specify dependencies for MonoBehaviours? * Would all your MonoBehaviours depend on concrete classes, since the editor doesn't serialize interfaces? What does this mean for mocking in your tests?
You can still make use of methods like OnTriggerEnter, Update, FixedUpdate etc, but many progammers will gravitate more and more towards encapsulating the logic associated with these things into pure C# classes that can be easily tested and swapped. As far as MonoBehaviours depending on concrete types, often yes this is unfortunately the case. However, I have another video planned regarding serializing Types which you will probably find interesting, in a few weeks or so. You can also use Odin to reference interfaces through the Inspector.
You're welcome. In that demo scene I actually also have the score system and the player controller implemented as MVC, but the ability system seemed to be the best one to show for the video since the view was more involved.
Yess part 2. can you also make a video how UI should me made with old UI system. I mean how to handle multiple canvases to decrease rerender the whole canvas or even make a separated UI scene
Not a bad idea, I'll put that on the list. There have been a lot of requests about UI Toolkit as well, but I think most people are still on the old system.
Great video as always! I am a seosoned Spring MVC developer and this explanation makes Unity so much approchable for me. Following your videos there is so much code and utilities I see myself using in my test after test projects. Would you recommend me to create my own unity packages with the systems you have explained? I guess the EventBuss would be tricky due to the assambly part...
Thanks! I think you could create packages if you wanted, it can be useful sometimes. Just remember that if you are creating an embeddable package it becomes immutable. I was thinking about making a video about this at some point. The Unity documentation is actually pretty good: docs.unity3d.com/Manual/CustomPackages.html and I recently moved the Unity-Utils repo to be a package that you can install from the git, you could look at that as an example.
Thanks for the video, it is a rare occasion to see such topics about MVC and Unity. Although MV* patterns (as well as Zenject and UniRx) are considered standard in post soviet countries (and I thought that it is caused by the fact that many devlopers came to game development having a enterprise app background where such features are a must). I am wondering how popular are MV* patterns in development studios? What other techniques are considered standard in your opinion? Also the topic of separation of concerns is very interesting to me, and is there any other methods like MV*?( as I understand that it isn't supposed to fit all scenarios)
To be honest, not too many people apply these kinds of patterns to their Unity games, but I would also say that MVVM could be included. But it's application might be as simple as separation of concerns with data binding. I think data binding will be the topic of a future video.
Great episode, it explains the topic very well, it’s pleasant to listen and watch. Being on the architectural patterns, can you say what you think about ECS? At first glance, it has the same advantages as MVC (encapsulation, data separation from behavior, etc.) but with contiguous memory usage and better performance. I would love to know your opinion.
Thanks for the comment, I appreciate that. ECS is very powerful, and I've been asked to talk about it many times - but I also wonder why. Do people struggle with it because it's a different (and more complex) paradigm, or possibly because Unity dragged it's feet in this area for so long that people lost interest - or has nobody been able to explain it in a manner that makes it approachable. I suspect it's the first reason. I wonder if showing a hybrid solution might get people interested. Maybe I'll read through some of the comments on a some newer content about it and figure out what's holding people back, might make a good video. What do you think holds people back the most from using ECS?
It seems to me that for a long time, the problem was the instability and backward incompatibility between versions. Looking at versions 0.5 and 1.0, it’s like a night and day (though in a good way). I even considered using svelto.ecs instead of Unity’s for quite a while.
But yes, I agree with you that the main problem is the paradigm shift in thinking.
How/where would you execute the abilities logic? What I've often encountered is that I have spells/abilities/whatever which highly vary in the things that they do. My first assumption is to have an abstract method where each concrete implementation would handle the logic in their own way. The issue I've encountered with that many times is that they often require different data passed onto them to perform the necessary logic, while the abstract definition clearly defines which parameters must be passed. It's a really annoying thing I've never managed to solve properly..
A lot of the small helpers are just in Gists - you can find all of that here: gist.githubusercontent.com/adammyhre/ Otherwise, check the Unity Utility repository here: github.com/adammyhre/Unity-Utils
That one is from the store - assetstore.unity.com/packages/2d/gui/cartoon-fantasy-gui-74743 The globes aren't animated though, so I would probably replace them with either ones from Moon Tribe: assetstore.unity.com/packages/2d/gui/icons/ultimate-health-bar-collection-178690 or Kronnect: assetstore.unity.com/packages/vfx/shaders/liquid-volume-pro-2-129967
Hey, I've been following your awesome channel for some time and I've been able to really capitalize on all the programming design knowledge you share. That being said, I'm having some trouble applying MVP (or rather framing it) for my current project: I have some purchaseable upgrades, each of which I want to put on a button on a scrollable list with its name on the button. When you hover over one of these an info window appears right next and inlcudes the name of the upgrade (again), its cost and a description. When you click the upgrade button it tries to spend your resources (which I've got in an ScriptableObject) and purchases and applies the associated upgrade. Though, I've tried a couple of times and consulted sources (as you said in the video, everyone puts a twist on the model), I'm not sure if I'm extracting the right things that each part of the architecture should expose. My thoughts are that: View is an observable and a "settable" that gets passed to the Presenter (either if view creates it or not); Model is again an observable for when it changes and a settable; Presenter gets the Model and View injected by the constructor and subscribes to view events and model events, additionally it exposes methods to take input from other systems. In my tries to model the architecture for my project I've tried to abstract these roles to reutilize them, because you can see it somewhat a complex list of views to update and handle correctly. But it just doesn't click that much.
It's clear you're putting a lot of thought into applying the MVP pattern to your project. It's important to remember that these architectural patterns lare fundamentally about separation of concerns. For your upgrades and scrollable list of buttons, consider the following: View: The View should be as dumb as possible - it displays what the Presenter tells it to and signals the Presenter about user actions (e.g., hovering over or clicking a button). The View doesn't know what happens when a button is clicked; it just knows to inform the Presenter of the click. Presenter: Receives inputs from the View (e.g., a button click) and decides what to do with them. It might check if the player has enough resources for the upgrade, update the Model accordingly, and then tell the View to display a success or failure message. The Presenter should be the one knowing which View to update and how, based on interactions and data changes. Model: Should notify the Presenter (not the View directly) when data changes, so the Presenter can update the View. Your ScriptableObject that tracks resources could be part of the Model. Your thoughts on making the View and Model observable and "settable" and having the Presenter manage interactions and updates are on the right track. The flexibility of MVP comes from the ability to abstract and reuse the Presenter and View logic for different parts of your UI, not from strict adherence to rules about what each component does. In practice, the boundaries can blur, especially in complex or interactive UIs. The key is to keep the core idea of separation of concerns in mind rather than sticking too rigidly to definitions. For instance, if it makes more sense for a complex interactive element to handle some of its own logic for performance or user experience reasons, that's okay as long as the overall structure remains clear and maintainable. Finally, it's perfectly normal to iterate on your architectural design as your project evolves. Sometimes, you only find the right abstraction level or component responsibilities through trial and error. Keep experimenting, and adjust the roles of Model, View, and Presenter as needed to best fit your project's needs.
Hello, the "Key" and the "Keyboard" in the AbilityButton class. from which namespace was it? it's not appearing on my Visual Studio. and when i tried the System.Windows.Input. the Keyboard class doesn't know about the "current" . sorry about the newbie question
Thanks, this has been really helpful and detailed! If I want to change what is being presented on the UI depending on what the player has selected, how would you go about that. Should the model be changed depending on the selection? Also if the data is to be changed at runtime I would guess I would probably not use a scriptable object and just use a normal c# class? For my use case I want to have selectable towns that have stats that change during play. Thanks again!
I would add functionality to the Controller so that it can change your model at runtime. The data could still be in scriptable objects, just pass the SO to the Model from the Controller. The Model can then change from using one SO to the new one for it's data. Remember that the Model isn't necessarily the same as data that you want to persist - but you can use it to read and write to a scriptable object.
Thanks for saying that there is something called "Over engineering". 😅🙏 People often conflate separation of concerns with over engineering but there's a big difference between writing quality code and adding unnecessary features. Over engineering happens when we lose sight of our actual needs and start building for hypothetical situations that may never occur. Quality code is about creating a system that's maintainable scalable and understandable. ruclips.net/video/v2c589RaiwY/видео.html
You can completely clear out the delegate list of a Unity button's onClick event by setting it to a new instance of the event, like button.onClick = new Button.ButtonClickedEvent();.
These patterns may appear complex at first, but are effective in handling complexity in larger or evolving projects. While less critical in smaller projects, the principle of Separation of Concerns is still a mark of quality coding in projects of any size.
yeah it doesn't matter if you're making something as simple as Flappy Bird and development would stop there. But once your project gets bigger, something as "simple" as a character controller in a Mario game with logic execution, data, and UI all in 1 MonoBehaviour class will make the class bloat to several thousand lines and heavily coupled. Any change to any element would affect multiple places, and bugs would become hard to track and unexpected. It's usually at this point when the programmer starts to think back and wondered if he had structured the code better, constrained the UI to what it does best (visual update) and only allow passing in necessary information for it to update, then he wouldn't have to shuffle up the entire class. Ease of access = ease of bugs. Something wrong with the visual? It's probably in the View class. The character turns left when your press right + down? Probably in the Controller. The character deals too much damage with an ability? Probably the model (stat bug) or controller (math bug). At the end of the day, it's all about preferences. If you find it unnecessary for your project, by all means just do it. Your coding style will develop as you code more, and you would gradually understand the important of code engineering.
I guess I’ve never worked on a project of that size that warrants this yet. I’ve made literally a hundred games without these and it’s been fine, but they were hyper casual games/ indie games. I find if I did this in those games it would have slowed us down quite a lot, but I had to rapidly prototype. So it seems this is really preferable for very large scale projects, in which case I would probably use Unreal anyway lol
@@JasonLovettGameDev the gain isn't in the development speed, it's in the maintenance. Slapping singleton and public static on everything is the fastest way to make games, albeit not very scalable nor maintainable. From what I've experienced, anything larger than hyper-casual requires some engineering else it would be a nightmare to fix, update, and add features. Unreal is probably when you wanna make AAA games lol.
Hey everyone, hope you find this video helpful in understanding Separation of Concerns with the MVC or MVP patterns. Code links are in the description. Let me know if you have more questions and if we need a 3rd episode on this topic!
First thing, great video!
I have been working as an Android Developer for 7 years now, implementing MVC, MVP and then MVVM in all my projects.
One note about the video, It is not best practice to tightly couple the Controller to the view, as then you lose what you wanted, which is separation of concerns.
In order to achieve that, you could use the Observer pattern and remove the dependency of the view from the controller.
This is desirable because it makes the code more testable, and you get the extra benefit that if you are going to make changes to your view, no changes are needed to your controller as it is truly separated.
I love your videos. I started my long-standing dream of game development and have been glued to all your videos since. Keep up the great work! 👍
Finally found a tutorial that not only talks about the three core MVC components, but also shows how to create and connect them. Really helpful.
Right on! Glad to hear that!
This is hands down the best gamedev/unity channel I've ever seen. Straight to the point, good practices, your own game examples for clips, nice explanations with graphics/diagrams, great voice with nice pacing, no BS memes/clickbait, no selfy video on the corner blocking views. Relatively short, but concise, no fluff. Excellent, excellent teacher.
Thank you for the kind words!
Great explanation and contextualization, as always.
MVC, MVP, and MVVM are staples of proper UI architecture in video games.
I'm glad that someone is finally taking the time to show people an actual implementation of one of them.
Well said! Thanks for the comment!
Your videos work for me as glue. Making all that I have learned come together. Now I have a new perspective and that's a big help, more than I could ask. Thank you very much.
You are so welcome!
I didn't know about UI because I wasn't interested in it, but after watching this video, I realized for the first time that there was such deep content. Kudos to you!!!!
Thanks!
Thank you for this super-useful video! Every time I see an update on your channel, I immediately know that there's a new video worth watching. Please keep up the good work!
You're very welcome!
finally someone is using diagrams for teaching and telling. The diagram at 4:00 makes many things clear.
Good to hear!
you're the greatest man, I needed this so much! I've been doing this all the time in my past years on web development, it didn't occur to me to try something similar for game development, this is great, thanks
You're very welcome!
Incredibly well done. The way you showed the diagram first, explained it, then jumped back and forth between code and diagram to show which part was being implemented was really helpful. Just found your channel, looking forward to checking out the rest of your content. Keep up the great work!
Thank you very much!
Loved the Unity Game Architecture series! Suggesting a playlist reorder for better flow: Start with 'SIMPLE Tip,' then 'Improve Your Unity Code with MVC/MVP,' and end with 'Learn Unit Testing.' Amazing work and best wishes!
Thanks! More to come!
Another great video! Glad to see there is at least one Unity youtuber who writes modern code.
Thanks for the kind words!
It is rare to have unity tutorials that go this deep. But this is exactly what I need to get to the next level! Thanks alot!
I just feel like having the videos in a series might be a good idea? When I watch this video there are some things I missed and having a structure/order in which to go through the videos would be great! Even if the reality is to watch all of them, episode number for example would indicate it well. But I understand the title has other needs as well...
Thanks for the comment! Unfortunately having an episode number on RUclips is a bit problematic because new viewers don't want to jump in if they feel like they need to commit to watching a bunch of earlier content, which makes it really hard to grow the channel. While I try to make every video stand on its own, if I reference something from an earlier video - like the Event Bus - I try to include a card in the video with the link. If you really want to watch it all, start with the Patterns playlist and then the Architecture one after that. These playlists are in the order the videos were made.
Your videos are fantastic keep it up 🙌
Thank you! Will do!
This is something I've heard for quite a while and seen a bit of it but never understand what it really is and how to really implement it, thank you for this video to make me understand a bit of it, might need to watch it couple times so i can really grasp the true idea, but as always a great video from Adam.. keep it up man, i know u will be big 😄
Thank you!
Seriously, thank you so much for putting out this level of content.
My pleasure!
Thank you for the detailed walkthrough. It would be awesome if you can introduce how to structure MVVM and data binding in Unity.
Thank you - actually data binding is on my list, I'll get to that one soon!
Another great video, I need to implement it to get my head around it though.
I'd be interested to see you go through a set of tutorials where you build out a game using the patterns, like a vertical slice of a game using the patterns. Would be a huge amount of work though I'd expect, and I would assume you already have plenty on your plate :D. Could be a paid course, I'd definitely pay for it.
Thanks for the comment! One of these days I'll take that course suggestion on, just need a month off work!
@@git-amendI imagine it would be a lot of work to setup. Either way I've learnt a ton from your videos , and look forward to every new one that comes out
+1 for a larger paid course, your videos are gold.
I hopr some people can learn from my mistake: I used the Event-Bus inside a system, which lead to a confjsing structure inside a mvp system. I learned that the Event-Bus is very nice for communicating between different mvp systems. Inside a system I used then simple public Actions on my view that forwards the events to the presenter and the presenter decodes what to do.
I dont know if this is the best approach, but it worked pretty well for me.
Another question: Would it be a good idea to have multiple views? (E. .g with 3 different interfaces) Currently I solve this by using 1 view that contains other "views" woth SerializeField.
Through out the years I have been bitching to my fellow software developer friends on how shitty every youtuber is when it comes to programming in unity. (from the perspective of a programmer)
I will like to thank you for spending time figuring out how to utilize great patterns and concept from the world of programming inside unity.
Working as professional software developer I know and work with a lot the patterns you show.
But I never really have the time to figure out how use it probably in unity.
Thank you for saving us time on "inventing the wheel"
Keep up the good work!
That is very high praise, thank you very much. More to come!
Nice video as always, and I've already started the MVC course on Udemy to learn more about it.
Great to hear!
Great content as always, said it before, but it is so great to have these intermediate videos in sea of for-beginner stuff! One question - in a game like Dragon age, where player can switch between different characters, would you have the MVC/MVP combo for each of the characters, or would you have just one and build the switching logic inside? Having it for each of the characters makes more sense for me, but id like to know your perspecitve :) Thanks!
Thanks! That's an interesting question. I think for a Dragon Age style I can see how having one for each character would make sense. Just be careful of any state that needs to be shared between them and take that into account somehow if necessary in case you have any data they all need access to or if they need to communicate with each other.
@@git-amend Will keep that in mind, thanks!
I was wondering if you were considering doing a video on developing features for a game w TTD? awesome stuff as always!
Maybe... but game devs don't like tests so much...
@@git-amend I certainly dont, and I have studied them some, but a lot of studios hiring seem to love to post them in the requirements for positions. In any case, I guess I hope you can get around to it, but its fine if not :)
ObservableList? i can feel a reactive programming episode coming😳😳
Haha maybe so!
I've always found the terminology around MCV to be rather unintuitive, but if I understand correctly, it's basically just saying to keep your Logic, Data, and Visuals all separate from each other.
Yeah, that's pretty much it.
Lets goooo! Thanks for this.
You bet!
Another video worth getting up early to watch. I thought that mvc/p would be hard to implement in Unity. Looks like it is worth using.
Thanks for watching! You must be west coast like me.
@@git-amendYes I am. I am on Vancouver Island. For some reason I thought you were on the east coast.
Nice, I lived in Sidney for about a year back in 2019.
@@techdave99 fellow vancouver island fella, you doing/did global game jam?
@@nuin99 no. i'm not really a jammer. Did you? what did you make?
Coming from Java Enterprise development, it's nice to see examples of how to implement those patterns in Unity. Great work! ⚔⚔⚔⚔ Where would you trigger SFX cues? Would you build an observer that listens to the Event Bus or inside the view?
Thanks! My first thought was just to say, yeah I'd have a separate observer on the Bus. However, maybe not for all sfx. If it was UI sfx, that really is part of the View I would think, like mouse click sounds etc, and doesn't have to be played in 3D space either. And, potentially you could also have sfx be played directly by the ability command with AudioSource.PlayClipAtPoint which creates an audio source at any point in the world. I guess in the end, it really depends... but I think for most, I would raise an event onto the bus and let another system handle it.
@git-amend There is a rogue if statement in the posting of the ability mvc system. In the gist line 145. The if statement doesn't belong to anything (not in a method) and throws an error. Also, AbilityCommand is not defined. Will post this in discord too.
Alright thanks, will look at it
Hi! Great video. I am also interested in PC movement. I notice that when PC jumps, camera doesn't follow. How do you achieve it? Thanks
Thanks, and great question. One day I'll make a longer video about building a custom player controller like this.
Basically, under the top most game object I have two children - one branch for the model and another branch for camera items. In the camera branch there is a 'camera target' game object which the camera aims at. So if something in the model branch moves, nothing in the camera branch moves, but the entire player moves them all. So essentially I'm achieving this by separating the model from the camera, but they both have the same parent.
@@git-amend Thank you for your answer. It helps me so much. I look forward to watching this video about player controller 🙏🏽
I am interested in this functonnality too.
Great video!
What are your thoughts on topics like "MVC is not used in games", adds to overhead, relies on data-binding... I really like this pattern and you explained it really good! But can't avoid feeling like maybe this isn't the best pattern for game dev? Do you know what companies architectural pattern usually uses? (avoiding custom architectures, obviously).
Would appreciate a brief explanation.
Continue doing videos like that, really good job!
Hey Adam, i have a question and maybe an idea, so whenever i want to create a new feature often i don't really know how many modules I'm gonna need and how deep it's going to be, so do you have tips on planning it like your flow chart.. thanks in advance
What I would do is start with a skeleton UML diagram so you can see it visually. A tool like excalidraw.com/ is very useful. Draw out your first draft and draw lines where you see dependencies - make sure none of them form a loop! Once you being coding, don't be afraid to refactor. Then go back to your diagram and update it, so you make sure it still makes sense to you. Just practice and never stop learning new things, and you'll get better and better at it. Your best tool is going to be experience and knowledge.
Have a read through the object and class diagrams sections of this page:
www.c-sharpcorner.com/UploadFile/nipuntomar/uml-diagrams-part-1/
@@git-amend thank you will check it for sure 👍
Great stuff, thanks! The past two videos made me wonder a couple things:
* What sort of gameplay stuff would you still do on MonoBehaviours? Do you delegate collision events and Transform-changes to non-Monobehaviours, too? (As with the Update(deltaTime) function.)
* I can see dependencies being injected in the non-MonoBehaviours, but would you still use the editor to specify dependencies for MonoBehaviours?
* Would all your MonoBehaviours depend on concrete classes, since the editor doesn't serialize interfaces? What does this mean for mocking in your tests?
You can still make use of methods like OnTriggerEnter, Update, FixedUpdate etc, but many progammers will gravitate more and more towards encapsulating the logic associated with these things into pure C# classes that can be easily tested and swapped. As far as MonoBehaviours depending on concrete types, often yes this is unfortunately the case. However, I have another video planned regarding serializing Types which you will probably find interesting, in a few weeks or so. You can also use Odin to reference interfaces through the Inspector.
Great tutorial! Do you think you could use a bigger font in the IDE in your future videos to make the code easier to read when watching on mobile?
When i include a future in my game i think about MVP/MVC if that feature needs to be implemented MVP/MVC, how to decide that correctly.
As a software engineer with few years of experience I can say that your channel could be very useful, thanks! What is your resume?
Thanks for the demonstration. I wonder what other use cases can be used with MVC/MVP pattern(apart from UI system).
You're welcome. In that demo scene I actually also have the score system and the player controller implemented as MVC, but the ability system seemed to be the best one to show for the video since the view was more involved.
Yess part 2. can you also make a video how UI should me made with old UI system. I mean how to handle multiple canvases to decrease rerender the whole canvas or even make a separated UI scene
Not a bad idea, I'll put that on the list. There have been a lot of requests about UI Toolkit as well, but I think most people are still on the old system.
Great video as always! I am a seosoned Spring MVC developer and this explanation makes Unity so much approchable for me. Following your videos there is so much code and utilities I see myself using in my test after test projects. Would you recommend me to create my own unity packages with the systems you have explained? I guess the EventBuss would be tricky due to the assambly part...
Thanks! I think you could create packages if you wanted, it can be useful sometimes. Just remember that if you are creating an embeddable package it becomes immutable. I was thinking about making a video about this at some point. The Unity documentation is actually pretty good: docs.unity3d.com/Manual/CustomPackages.html
and I recently moved the Unity-Utils repo to be a package that you can install from the git, you could look at that as an example.
@@git-amend gr8! thanks
Thanks for the video, it is a rare occasion to see such topics about MVC and Unity. Although MV* patterns (as well as Zenject and UniRx) are considered standard in post soviet countries (and I thought that it is caused by the fact that many devlopers came to game development having a enterprise app background where such features are a must). I am wondering how popular are MV* patterns in development studios? What other techniques are considered standard in your opinion? Also the topic of separation of concerns is very interesting to me, and is there any other methods like MV*?( as I understand that it isn't supposed to fit all scenarios)
To be honest, not too many people apply these kinds of patterns to their Unity games, but I would also say that MVVM could be included. But it's application might be as simple as separation of concerns with data binding. I think data binding will be the topic of a future video.
Awesome stuff!!
Thanks!
Great episode, it explains the topic very well, it’s pleasant to listen and watch. Being on the architectural patterns, can you say what you think about ECS? At first glance, it has the same advantages as MVC (encapsulation, data separation from behavior, etc.) but with contiguous memory usage and better performance. I would love to know your opinion.
Thanks for the comment, I appreciate that. ECS is very powerful, and I've been asked to talk about it many times - but I also wonder why. Do people struggle with it because it's a different (and more complex) paradigm, or possibly because Unity dragged it's feet in this area for so long that people lost interest - or has nobody been able to explain it in a manner that makes it approachable. I suspect it's the first reason. I wonder if showing a hybrid solution might get people interested. Maybe I'll read through some of the comments on a some newer content about it and figure out what's holding people back, might make a good video.
What do you think holds people back the most from using ECS?
It seems to me that for a long time, the problem was the instability and backward incompatibility between versions. Looking at versions 0.5 and 1.0, it’s like a night and day (though in a good way). I even considered using svelto.ecs instead of Unity’s for quite a while.
But yes, I agree with you that the main problem is the paradigm shift in thinking.
Thanks for excellent tutorial .. like always. May i ask, what software do you use for you diagrams? They look really nice!
You’re welcome! Right now I use SketchWow but I’m going to try Excalidraw this week
How/where would you execute the abilities logic? What I've often encountered is that I have spells/abilities/whatever which highly vary in the things that they do. My first assumption is to have an abstract method where each concrete implementation would handle the logic in their own way. The issue I've encountered with that many times is that they often require different data passed onto them to perform the necessary logic, while the abstract definition clearly defines which parameters must be passed.
It's a really annoying thing I've never managed to solve properly..
Typically I use the Command pattern for this. Each command is different, but can employ it's own Strategies for targeting, effects and so on.
is there any utility folder or collection that I can find of yours which includes features like CountDownTimer, observablelist and etc.
A lot of the small helpers are just in Gists - you can find all of that here: gist.githubusercontent.com/adammyhre/
Otherwise, check the Unity Utility repository here: github.com/adammyhre/Unity-Utils
@@git-amend thank you very much I will work on them
How did you create your UI? Is it an asset pack? Im checking for some good looking globes I can use and these look amazing
That one is from the store - assetstore.unity.com/packages/2d/gui/cartoon-fantasy-gui-74743
The globes aren't animated though, so I would probably replace them with either ones from Moon Tribe:
assetstore.unity.com/packages/2d/gui/icons/ultimate-health-bar-collection-178690
or Kronnect: assetstore.unity.com/packages/vfx/shaders/liquid-volume-pro-2-129967
Hey, I've been following your awesome channel for some time and I've been able to really capitalize on all the programming design knowledge you share. That being said, I'm having some trouble applying MVP (or rather framing it) for my current project:
I have some purchaseable upgrades, each of which I want to put on a button on a scrollable list with its name on the button. When you hover over one of these an info window appears right next and inlcudes the name of the upgrade (again), its cost and a description. When you click the upgrade button it tries to spend your resources (which I've got in an ScriptableObject) and purchases and applies the associated upgrade.
Though, I've tried a couple of times and consulted sources (as you said in the video, everyone puts a twist on the model), I'm not sure if I'm extracting the right things that each part of the architecture should expose.
My thoughts are that: View is an observable and a "settable" that gets passed to the Presenter (either if view creates it or not); Model is again an observable for when it changes and a settable; Presenter gets the Model and View injected by the constructor and subscribes to view events and model events, additionally it exposes methods to take input from other systems.
In my tries to model the architecture for my project I've tried to abstract these roles to reutilize them, because you can see it somewhat a complex list of views to update and handle correctly. But it just doesn't click that much.
It's clear you're putting a lot of thought into applying the MVP pattern to your project. It's important to remember that these architectural patterns lare fundamentally about separation of concerns. For your upgrades and scrollable list of buttons, consider the following:
View: The View should be as dumb as possible - it displays what the Presenter tells it to and signals the Presenter about user actions (e.g., hovering over or clicking a button). The View doesn't know what happens when a button is clicked; it just knows to inform the Presenter of the click.
Presenter: Receives inputs from the View (e.g., a button click) and decides what to do with them. It might check if the player has enough resources for the upgrade, update the Model accordingly, and then tell the View to display a success or failure message. The Presenter should be the one knowing which View to update and how, based on interactions and data changes.
Model: Should notify the Presenter (not the View directly) when data changes, so the Presenter can update the View. Your ScriptableObject that tracks resources could be part of the Model.
Your thoughts on making the View and Model observable and "settable" and having the Presenter manage interactions and updates are on the right track. The flexibility of MVP comes from the ability to abstract and reuse the Presenter and View logic for different parts of your UI, not from strict adherence to rules about what each component does.
In practice, the boundaries can blur, especially in complex or interactive UIs. The key is to keep the core idea of separation of concerns in mind rather than sticking too rigidly to definitions. For instance, if it makes more sense for a complex interactive element to handle some of its own logic for performance or user experience reasons, that's okay as long as the overall structure remains clear and maintainable.
Finally, it's perfectly normal to iterate on your architectural design as your project evolves. Sometimes, you only find the right abstraction level or component responsibilities through trial and error. Keep experimenting, and adjust the roles of Model, View, and Presenter as needed to best fit your project's needs.
I'm really curious about which software are you using to draw your diagrams :O
I have been using SketchWow, but I think I might try Excalidraw for the next video
Hello, the "Key" and the "Keyboard" in the AbilityButton class. from which namespace was it? it's not appearing on my Visual Studio. and when i tried the System.Windows.Input. the Keyboard class doesn't know about the "current" . sorry about the newbie question
docs.unity3d.com/Packages/com.unity.inputsystem@1.8/api/UnityEngine.InputSystem.Key.html
The Key enum is from Unity's New Input System.
@@git-amend Oh thanks! I'll check later if it's available in Unity 2022.2f
sorry is this continuation of series? if yes i was not able to find other parts.
It is not part of a series.
Thanks, this has been really helpful and detailed! If I want to change what is being presented on the UI depending on what the player has selected, how would you go about that. Should the model be changed depending on the selection? Also if the data is to be changed at runtime I would guess I would probably not use a scriptable object and just use a normal c# class? For my use case I want to have selectable towns that have stats that change during play. Thanks again!
I would add functionality to the Controller so that it can change your model at runtime. The data could still be in scriptable objects, just pass the SO to the Model from the Controller. The Model can then change from using one SO to the new one for it's data. Remember that the Model isn't necessarily the same as data that you want to persist - but you can use it to read and write to a scriptable object.
Thanks for saying that there is something called "Over engineering". 😅🙏
People often conflate separation of concerns with over engineering but there's a big difference
between writing quality code and adding unnecessary features. Over engineering happens when we lose sight of our actual
needs and start building for hypothetical situations that may never occur. Quality code is about creating a
system that's maintainable scalable and understandable.
ruclips.net/video/v2c589RaiwY/видео.html
You're welcome! 😀
Hello!
How do you unsubscribe a button if you subscribed a method to it via a lambda?
You can completely clear out the delegate list of a Unity button's onClick event by setting it to a new instance of the event, like button.onClick = new Button.ButtonClickedEvent();.
Nice.
Thank you! Cheers!
@@git-amend you don't need to respond if you don't want too, i just want to boost the algorithm.
@@damonfedorick Any you've boosted it again - which I appreciate haha!
Why does this feel like it makes things way more complicated than it has to?
These patterns may appear complex at first, but are effective in handling complexity in larger or evolving projects. While less critical in smaller projects, the principle of Separation of Concerns is still a mark of quality coding in projects of any size.
yeah it doesn't matter if you're making something as simple as Flappy Bird and development would stop there. But once your project gets bigger, something as "simple" as a character controller in a Mario game with logic execution, data, and UI all in 1 MonoBehaviour class will make the class bloat to several thousand lines and heavily coupled. Any change to any element would affect multiple places, and bugs would become hard to track and unexpected.
It's usually at this point when the programmer starts to think back and wondered if he had structured the code better, constrained the UI to what it does best (visual update) and only allow passing in necessary information for it to update, then he wouldn't have to shuffle up the entire class. Ease of access = ease of bugs. Something wrong with the visual? It's probably in the View class. The character turns left when your press right + down? Probably in the Controller. The character deals too much damage with an ability? Probably the model (stat bug) or controller (math bug).
At the end of the day, it's all about preferences. If you find it unnecessary for your project, by all means just do it. Your coding style will develop as you code more, and you would gradually understand the important of code engineering.
I guess I’ve never worked on a project of that size that warrants this yet. I’ve made literally a hundred games without these and it’s been fine, but they were hyper casual games/ indie games. I find if I did this in those games it would have slowed us down quite a lot, but I had to rapidly prototype. So it seems this is really preferable for very large scale projects, in which case I would probably use Unreal anyway lol
@@JasonLovettGameDev the gain isn't in the development speed, it's in the maintenance. Slapping singleton and public static on everything is the fastest way to make games, albeit not very scalable nor maintainable.
From what I've experienced, anything larger than hyper-casual requires some engineering else it would be a nightmare to fix, update, and add features. Unreal is probably when you wanna make AAA games lol.
Thanks for the replies, I actually agree. Really appreciate the feedback as it helps crystalize it in my mind.@@Briezar
Thanks!
Yo my man just drop a bomb
Thanks!