Unity3D Managers vs Controllers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Oh wow, I definitely thought that was Dan Harmon in the thumbnail

👍︎︎ 2 👤︎︎ u/detectonomicon 📅︎︎ Jun 27 2018 🗫︎ replies

Great! I just finished your tutorials on SOLID principles! Keep up the good work and take my upvote!

PS: I love your work in Rick and Morty! LUL kidding

👍︎︎ 2 👤︎︎ u/yuffiecross 📅︎︎ Jun 28 2018 🗫︎ replies
Captions
hey what's up Jason here from unity3d college today we're going to talk about managers controllers and systems we're going to go over what they are what these terms mean in game development and how you should or should not use them let's start with the manager the key thing that managers tend to do is provide a way to interact with a collection of objects so if you think of a entity manager or you know a spawn manager or an enemy manager or rocket manager or whatever the hell it is it's going to have a collection of different types of things or usually it's a collection of a bunch of one type of thing an NPC manager for example may have a method to get all of the NPC's within a specific range so this manager is keeping track of the NPC's when we add or create new NPCs they're going right into it and when we remove them they're coming out of it and it knows their position maybe a little bit of information about them and we can use it just to find the correct NPCs or to kill off an NPC well maybe we have a process that needs something needs to happen when NPCs die the NPC can die tell its manager that it's going going away that manager can then kick it back into a pool it can handle any cleanup that needs to be done send off any events or messages that need to be known about in other systems and kind of wrap things up nice and cleanly it also gives us an easy can a shared common way to find or get these entities for instance if we want to have a player manager to get players it's a whole lot better than having a bunch of player game objects just sitting in the scene and then trying to in our other code find the correct player so I've talked a little bit about what managers do now I just want to talk about how they're generally created usually you'll see a manager as a singleton or just a single instance of it in a scene or loaded at a time so if we have an entity manager we're not going to have multiple entity managers we're probably gonna start one up right at the beginning of our project and just leave it there now it may be a per scene think perhaps we don't care about entities once the scenes gone so we just create the entity manager it gets everything ready at the beginning fills it up and then gets destroyed and we get a new one but you're never gonna see or at least not in a good system a situation where you have multiple of the same type of manager just loaded up in the scene it's also important when you're creating these managers to make sure that they're not doing too much that they're really just handling interactions with these objects or providing a way to interact with the objects to other classes so they're giving you a way to find an npc and do something to that NPC or to launch a rocket or destroy a rocket or something like that but there is this idea of creating a game manager that just runs the entire game flow so this this kind of thing that has some setup in it it runs kind of what's going on through the different stages of the game when the player should transition to the next stage or when the level should switch and this doesn't really match up with all of the other manager stuff that I've talked about so far but it's still a fine use for a manager naming system it's just a totally different implementation now I do want to talk a little bit more about these though because game managers tend to work great on smaller projects if you have something like for instance the balls game that I recreated recently you could easily shove all of the data all of the state right into that game manager have the whole flow be there and have it totally make sense and be readable extendable and good to go but imagine if you're diving into a slightly bigger project perhaps it's an MMO or maybe it's a think of your most advanced first-person shooter that you play and I think of like overwatch I like to play that a lot over a watch with a game manager like I'm just thinking through what does the game manager do it can't really do one thing there's just so much going on in a game like that or like said in these even larger games think of a big RPG just about anything that's not a small mobile game think about what a game manager would have to do and if what it has to do is a whole ah no crap then you're really just kind of shoving your entire game into one class you're not really creating a manager so much as a big giant mess that's gonna be a nightmare to deal with later but what about controllers what's a controller and how does that differ from a manager so generally controllers tend to be something that goes on a specific entity or game object so this could be on an NPC it could be on a ball that's just bouncing around in your game it's just something that is there to orchestrate and control other components or kind of run that entire game object depending on the object if it's small enough your controller may be you know controlling the entire object you know like if it's a simple again going back to that balls demo if it's a ball you could have a simple ball controller that just tells it to launch up in a direction that's it now sometimes the word controller just isn't added here as well so if it's controlling a specific entity type you know like it's an NPC you may just see NPC instead of NPC controller totally fine I tend to go back and forth on that depending on just how much state is in there if there's not really much state it'll usually be something that's more of a controller for me and then if it has a lot of state I'll usually drop that word out and this is just somewhat of a habit of my own and I don't think it really makes that much sense either let's go over a couple controller examples so a big one that you'll see a lot is something like a player controller and generally this isn't very well defined it tends to read input handle moving sometimes handle shooting handle all kinds of things it's usually a slightly over encompassing term that doesn't really tell you what the thing is doing or what the script is doing it just tells you hey this is doing player related stuff I ideally I like to have smaller controllers things like a navigation controller that's just responsible for figuring out where this thing wants to go and how wants to get there and it could be doing something as simple as tying into a nav mesh agent calculating out a path and then setting that path or an animation controller that handles changing to different animation States maybe send some information into the Meccan M system to control blends or transitions switches or anything like that going a little bit deeper if I'm building a game with lots of stats in it so maybe for instance just thinking of a real project an MMORPG it's got no strength health intelligence resists all that kind of stuff I'd like to have a stats controller there that's just responsible for that stats thing and then this this helps because I can segment the stuff off get a nice small class that's just responsible for stats and I can also reuse that across other things so if I want to have you know an object that has stats on it that's maybe not a player or not an NPC I can just drop that stats controller onto there and if I've coded it up you know and abstracted it away enough it should just kind of fit on there and work with very minor revision or very minor external work I shouldn't have to do much to make it just work with anything one other really common type of controller is the input controller and it's just responsible for reading input for a specific player this could be on an entity it could be on multiple entities and each one of those would be responsible for reading input from a different player ideally so it'd have like a player set up with a player may be a player controller on it probably not but definitely with an input controller on there and then that would be responsible for reading input from that player probably through an input system and then passing that information on to the rest of the entity so on to the player so it goes something like I've got a player I've got a input controller and maybe I've got a navigation controller the input controller is feeding an input to the player which is then sending that back out to things like that navigation controller may be an attack controller or an ability or spell controller that's handling when I cast spells so they're not really tightly coupled which is what I want to go for I want to keep these nice small and separated but they all can kind of tie in and work well together so I can kind of mix and match the pieces that I need to build the functionality that we want to have so what about the term system what do you think of when when we're building out a system in game now when I sent out the poll the results that I got were pretty interesting and a lot of people just don't like using the term system at all and I generally agree usually a system is more of a combination of controllers and managers and other code and it's this whole idea and thought of bringing a thing together and creating this entire system so for instance if I've got an ability system in it it may be built up of multiple different controllers and other classes that are all just kind of tying stuff together and I don't really think of it as a single class but there are some cases where I'll build a system class things like an input system think of it for instance the networking systems built into unit those are all names with system as well but there is a system that's a little bit different that I think we should talk about briefly which is something like the entity component system and the systems and they're designed to work on a set of data every frame and just keep updating it so an example would be the movement system or the was it the vector3 movement system in ECS it just takes in objects that have a vector3 component on them and then moves them in whatever direction they're heading I think it actually takes in ones that have a vector3 a heading and the speed all set and then it moves them along in that direction now those systems are cool and I think the ECS is very interesting but not really applicable to most day-to-day game development stuff that everybody watching this is doing so if you're in DCs it's awesome I think it's pretty interesting stuff but other than that systems generally again tend to be more of a bigger abstract thing not something that you see so much in code and before I wrap this up I just want to mention that when you're doing all this stuff when you're creating these systems and controllers and managers and naming things the most important part here is to just be really consistent keep your manager's name manager controllers named something controller if you're building UI components of one of the things I like to do is add UI to the script so start with UI right at the beginning so it's very obvious that this is a UI script or you know sometimes would be a UI controller I don't know it's still gonna have the UI in it just make sure that you keep your things named cleanly nicely it'll make it easier for you and for the other developers on your project so that's all I've got for today hopefully this was kind of helpful if you have questions about managers controllers naming stuff or any of that in general or just want to leave some you know feedback of your own comments on things that you think are wrong here or other suggestions or make things better please just drop a comment below other than that don't forget to Like subscribe and all that fun stuff and have a great day
Info
Channel: Jason Weimann
Views: 41,820
Rating: undefined out of 5
Keywords: unity3d, unity, unity tutorial, unity3d tutorial, unity controller, unity manager, unity3d controller, controllers vs managers, unity3d systems, unity game engine, unity 3d, unity (software), unity manager singleton, unity game manager, unity manager vs controller, unity tutorial 3d, unity manager scene, unity3d college, unity3d game tutorial, unity3d 2018, unity tutorial for beginners 2018, unity software
Id: T39tyyQjFSQ
Channel Id: undefined
Length: 12min 6sec (726 seconds)
Published: Tue Jun 26 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.