This is probably the single most helpful Unity-related channel on RUclips I've found so far. A real hidden gem. I feel like 99% of tutorials encourage just copying the code, without really explaining the thought process. And while the solutions they offer are fine, they're also out of context and not really applicable to even slightly bigger projects - that's how you get those monster classes. When you're trying to get into these things by yourself, those kinds of tutorials do more harm than good in a long run and encourage bad practices. Or maybe it's just a natural thing, doing stuff the wrong way to get started and then learn how to do it properly, I'm not sure. Anyway, I'm really thankful for videos/articles about architecture and programming patterns, you're one of the few people who can explain how these things work and what the benefits are, in a way that I almost instantly get it. Can't thank you enough Jason, your videos have been invaluable and I've learned more in a couple of months than I've learned previously in almost two years. You deserve a lot more views/subs. PS: I have an idea for a video if you don't mind: how about some Unity workflow tips, shortcuts or other fun stuff that you often use when working in the editor? That could be super handy to a lot of people.
I know that your comment is 10 months old but I feel the same way! It was so hard to find these videos, although I was looking for it. I just didn't know what I'm exactly want to find. It's shame that everyone knows Brackeys content when it's not that helpful (sometimes harming as you said). Anyway, I'm really thankful for your videos Jason!
These videos are awesome. The more flashy Unity RUclipsrs like Brackeys and CodeMonkey have very good tutorials also. But the great thing about your tutorials is that you don't just give us a specific way to do one thing, but teach us the principles not only for Unity for coding all together. I believe lot of your viewers are self taught people and the basic principles are the things that the coder easy skips when starting. I have a CharacterAI script in my game that I have been splitting apart a bit to achieve this, but it's still about 600 lines long.
I'm really bad at coding and I'm outta here speechless how lucky I am to find this channel explaining things that saved my motivation in becoming a game developer. Thank you so much good sir! I will do my best to improve and to make a game that everyone will love to play. Once again, thank you!
This clearly answered my questions for porting an existing Windows application with heavy class structure to Unity. Brilliant. Thanks Jason. You are doing some good work here.
Oh man! You are the programming guru I've always wanted... a true master! Deep understanding of the principles coming from real-world professional experience. You're clear, charismatic as necessary, and cover countless principles that I've only vaguely understood or are completely new to me -- and useful! Thank you so much!
This is supporting what I do for some time now, making the object an organic 'disciplines' classes. A. Stats, B. Autonomous, C. Actions, D. Responses, E. Extra (or whatever A,B,C,D,E are needed).
Four minutes into your tutorial, I found what I needed. I just wanted to know how to add inheritance from a Non-Unity C# class into derived classes of Unity so that I could use Inheritance like a normal programmer, else all it is, is a scripting language and that would be a waste. Much appreciation, it is hard to find people who are intuitively insightful to answer our "newbie" questions. public class Humanoids : Monobehavior { } public class EventManager : Humanoids { } So easy but hard to make that bridge with out knowing this.
Thanks Jason, instead of just the classic, animal, dog/cat example, you used functions and also showed how protected virtual and override is used. Makes so much sense why this is useful or at least time saving! Keen to play around with it and keep improving my code!
I understand both Inheritance and Composition, but honestly it feels a lot more "natural" to use Composition in the context of programming a game. This is a great video, thank you.
It seems to me that the component structure makes more sense if you find it first. I started programming around the time OOP and inheritance were the natural law. I think I'm liking composition for Unity development, but it's taking me a surprising amount of effort to think about it as clearly as I do inheritance.
Thanks so much for this. Just getting started in Unity (last time I did any REAL programming was in actionscript 3, lol) and this really helped clear my head regarding how to re-use and organize code intelligently. Unity is in many ways pretty similar to the flash IDE actually. Learning to move AWAY from such heavy inheritance that I was being taught back in the day is refreshing.
Really appreciating your Clean Software Design topics! Composition is a very powerful feature of the Unity Engine. It is a style of ObjectOrientedProgramming that was passed over by most of the mainstream systems. I recall touting it back in 80s for modeling/animation software but not finding good support in languages, etc.
Great talk. The proper way to use ECS archtecture is definately via Composition. You explained the concept really really well, i would love to see you talk more about SwArchtecture in Unity, subscribed.
This is awesome!!! I'm a C# newbie and found this to be a very valuable high-level explanation of how to think about setting up game code. Thank you for making this! Time to go make a bunch of "behavior legos" and build cool things out of them. : D
on 11:30 it should be a RequireComponent inside the CharacterMovement class, because its the one that needs PlayerInput, the latter does not need CharacterMovement to work.
You can make inheritance follow the solid principles easily if you segregate well. Eg NPC should never have a 'combat' functionality by default since it is supposed to describe a plain living entity, which doesn't necessarily have to be able to fight. If you use OOP and inheritance correctly you will only project the functionality on the classes, that reflect their most basic 'actual form'
As an Unreal Engine programmer it was interesting video, i've received some decent ideas about architecture in general bc im a noob :D. It was really interesting and helpful, thanks
I really liked this video, specially at this time, I have been stuck in a project which is a mess. And we need to add a multiplayer mode in it. I think some refactoring would help. Thanks for these videos It helps alot.
So incredibly helpfull and important information, thank you! I was always stuggling how to put things together and I was searching ALOT for this kind of info. This should go into the Unity Coding series!! You learn all sorts of things about what is what, syntax and so on, but a more distant overview about projects, coding in general was missing badly. One thing I'm still missing is the actual input when coding, like shortcuts, comment things out quick, how did you changed the first letter so quick, how to implement a method part when you wrot just the methods call in update and much more. Would mucho appreciate a tutorial or just tell your favorite shortcuts/techniques. Anyway, keep it up! Good stuff! Greetings from Germany
I like your videos! Will you continue this playlist by teaching us Design Patterns applied to Unity game programming? I mean not only classical Singleton, Object Pooling and State Machine, but also others like Factory, Adapter ect.?
Guilty as charged. I've worked on my game for a year(on and off). Nearly finished the base game, but realized that the gameplay design was wrong and the complexity of large pieces of codes made me want to push my fingers into my eyes. So I've stopped. Now I've finally redesigned the gameplay after months and all I needed was this. Thanks. I'll start cutting up my code into little pieces.
Really useful thank you, how do you decide when you should use a component for health or use an interface that "forces" a class to have hp if that makes sense?
By the 12:50 you talk about events... It can be used that idea in a multiplayer project? Like, classes inheritance and events? If so, do you have something like that more specific?
Thanks for another brilliant video. I wish I had the money to do your courses, they're sadly out of my price range, but I'm very grateful that you give so much of your expertise for free on RUclips :) Can I ask... with composition is there a way to know or enforce the order in which the various components are acted on? Does the order in the Inspector make any difference? I know about Script Execution Order Settings but I can see this getting very convoluted on a large project with multiple scenes. I guess there's also the option of choosing carefully between initialising things in Awake() or Start(). Just wondered if you had any tricks or recommendations for this?
Hey, I am curious, would you prefer a public static event OnDied in the health class or having the pooling system actually have a reference to health Component?
I've a doubt.. If I have a script that manages weapon firing... If I have a weapon that fire 1 bullet once and another that fire 3 with different angulation.. Is better to do a inheritance (do another script that change the base class), or composition, so i do one script for firing like the first case, another for the second?
I also want to do a system where there are some weapons that need charging before firing the first bullet (like a minigun) and others not.. In your opinion is better composition or inheritance? (Sorry for stupids questions)
(For the last questiob) I want to do composition but I don't know how to do that if there is the component, before firing, the weapon need to wait.. Should I use event (I can't use them)?
@@sconosciutosconosciuto2196 Ever seen that video called, "Ability System with ScriptableObjects"? You should consider adding methods to a 'Bullet' ScriptableObject that your weapon can use. Then, make an SO that inherits from Bullet, call it something like 'SplitBullet', give it a different Fire() method, and you're good.
I've always felt like the unity component system was screaming for composition and make it extremely easy to manage ! The only time I dealt a lot with inheritance was for my rpg equipment/inventory system and it was much more complicated...
Nice, thanks for all these tutorials! Can you create a tutorial on a bubble burst games? Like when you click on the bubble, it pops. I'm trying to do this, but can't figure out how to switch back from a bubble image --> popped image with the prefabs and animations I've created.
Can you maybe start a series of making a RPG game - you know because of the complexity of how most classical RPG's work (but not as complex as an MMO) and also make it 2D for simplicity sake - The point being is - you are full with knowledge and if we would have such a series, we would learn first hand from you design patterns, best practices, real life solutions in specific scenarios.. damn make it on udemy if you like - shut up and just take my money (I am kidding - don't shut up keep it comming) :)!
I'm composing a lot of scripts in my current project by having a Manager class that decides when to use which script: for example disabling and enabling different camera or movement scripts. Do you think this is a good method or inefficient somehow?
Thats great thanks! Ill go with composition from now on, it seems much easier to write and also to maintain!! Just a question after using the composition Health class, how do you access its TakeDamage() method from another class? Would it be the same thing as inheritance? ie. you have to first find the object by tag and then use "npc = GetComponent" and then use "npc.takeDamage" ?? or is there another better way to do it? thanks
You can use an interface in the Health class and receive hits from enemies by accessing the class, regardless of who it is, the Observer pattern will be executed
Very nice tutorial. It just seems weird to inherit from monobehaviour when a class doesn't need its functionality, like in your health class. Maybe I'm thinking about it wrong...
it does, but there may be common stuff in the base class you want to call as well. One of the problems is knowing when this is a must to not break stuff or not.
so, if you call base.Update(), it will call whatever is in the base class Update, but if you just call the override Update(), with custom functions, it will do the custom functions?
I'm the opposite, I prefer inheritance. Clear line of hierarchy with classes. You don't end up mixing and matching making it much easier to follow the code.
@@Scottx125Productions I'm in the same boat as you. Inheritance just makes more sense to me. But I'm finding that it has problems when we don't know the full scope of our application from the start, which can lead to a great deal of refactoring. It seems easier to follow single-responsibility when using components, so I'm starting to like components more. It does seem that Unity prefers this approach, as well, but it's difficult for me to switch my brain over from inheritance to composition.
I think what annoys me about the whole component system is that in your example and many others, these components still depend on one another. CharacterMovement still needs the NavMeshAgent and is useless without it. This is not a criticism of your design, but rather this idea that "you can mix and match components and it just works" but you really cannot in many cases because they usually need to communicate in some way.
I love your videos but the OnDied event name is horrible :) Event names should be Verb-ed only, like Died, Closed, Shown. OnXXX format is used for override(virtual) methods only :)
- starts showing an inheritance design - continues to mess up the inheritance design - points out that inheritance doesn't work well Lol, if you want to have a Merchant in your design it should not inherit directly from your NPC class. Inside the NPC class you have some combat logic, not all NPC's do combat. Instead you should have a CombatNPC class that inherits from the NPC and put the combat logic there. This way, the Merchant could inherit from the NPC correctly with no problem at all.
You are really one of the best youtubers on Unity and programming tutorials. Thank you veru much!
thanks :)
This is divine truth.
facts
@@McNottagoose No, it's not. For true divine intellect go watch Terry Davis instead
@@--8251 ha damn thats a grave dig. But I agree, I have since found the truth that is terry davis may his genius soul rest in peace
This is probably the single most helpful Unity-related channel on RUclips I've found so far. A real hidden gem.
I feel like 99% of tutorials encourage just copying the code, without really explaining the thought process. And while the solutions they offer are fine, they're also out of context and not really applicable to even slightly bigger projects - that's how you get those monster classes. When you're trying to get into these things by yourself, those kinds of tutorials do more harm than good in a long run and encourage bad practices. Or maybe it's just a natural thing, doing stuff the wrong way to get started and then learn how to do it properly, I'm not sure.
Anyway, I'm really thankful for videos/articles about architecture and programming patterns, you're one of the few people who can explain how these things work and what the benefits are, in a way that I almost instantly get it. Can't thank you enough Jason, your videos have been invaluable and I've learned more in a couple of months than I've learned previously in almost two years. You deserve a lot more views/subs.
PS: I have an idea for a video if you don't mind: how about some Unity workflow tips, shortcuts or other fun stuff that you often use when working in the editor? That could be super handy to a lot of people.
Thanks! That's a great video idea too, will have to figure how to structure it, but I think it'd be worth doing for sure :)
I know that your comment is 10 months old but I feel the same way! It was so hard to find these videos, although I was looking for it. I just didn't know what I'm exactly want to find. It's shame that everyone knows Brackeys content when it's not that helpful (sometimes harming as you said). Anyway, I'm really thankful for your videos Jason!
Yep, totally right. I found this channel via facebook on unity college by luck.
This video and the SOLID principles video should be mandatory for everyone ... not just Unity, but for life in general.
These videos are awesome. The more flashy Unity RUclipsrs like Brackeys and CodeMonkey have very good tutorials also. But the great thing about your tutorials is that you don't just give us a specific way to do one thing, but teach us the principles not only for Unity for coding all together. I believe lot of your viewers are self taught people and the basic principles are the things that the coder easy skips when starting. I have a CharacterAI script in my game that I have been splitting apart a bit to achieve this, but it's still about 600 lines long.
the [RequiredComponent(typeof(T))] was EXTREMELY helpful. Thank you!
I love it when you mention something not specific to the video, but you go ahead and explain it.
I learnt heaps, thanks!
I'm really bad at coding and I'm outta here speechless how lucky I am to find this channel explaining things that saved my motivation in becoming a game developer. Thank you so much good sir! I will do my best to improve and to make a game that everyone will love to play. Once again, thank you!
This clearly answered my questions for porting an existing Windows application with heavy class structure to Unity. Brilliant. Thanks Jason. You are doing some good work here.
I'll admit I make monster classes all the time. Thank you so much for this, I'll definitely be using composition in the future!
We've all done it :) I spent years making them before I found the light ;)
I think I just make way too many little classes.
You've EASILY become my favorite source to learn more about Unity 😁 Thanks for all the great content! ✊
Oh man! You are the programming guru I've always wanted... a true master! Deep understanding of the principles coming from real-world professional experience. You're clear, charismatic as necessary, and cover countless principles that I've only vaguely understood or are completely new to me -- and useful! Thank you so much!
Probably the single most helpful video I've ever seen when it comes to code design in Unity.
This is supporting what I do for some time now, making the object an organic 'disciplines' classes. A. Stats, B. Autonomous, C. Actions, D. Responses, E. Extra (or whatever A,B,C,D,E are needed).
Thank you for covering this. I am a fan of the composition structure myself, but maybe that's because it's easier for my head to wrap around it.
Agreed, it makes it much easier to grasp the project
Four minutes into your tutorial, I found what I needed. I just wanted to know how to add inheritance from a Non-Unity C# class into derived classes of Unity so that I could use Inheritance like a normal programmer, else all it is, is a scripting language and that would be a waste. Much appreciation, it is hard to find people who are intuitively insightful to answer our "newbie" questions.
public class Humanoids : Monobehavior { }
public class EventManager : Humanoids { }
So easy but hard to make that bridge with out knowing this.
Awesome! Glad to hear it was helpful :) Inheritance is an amazing tool to have available.
Thanks Jason, instead of just the classic, animal, dog/cat example, you used functions and also showed how protected virtual and override is used. Makes so much sense why this is useful or at least time saving! Keen to play around with it and keep improving my code!
I understand both Inheritance and Composition, but honestly it feels a lot more "natural" to use Composition in the context of programming a game. This is a great video, thank you.
It seems to me that the component structure makes more sense if you find it first. I started programming around the time OOP and inheritance were the natural law. I think I'm liking composition for Unity development, but it's taking me a surprising amount of effort to think about it as clearly as I do inheritance.
@Jason Weimann
Inheritance 0:43
Composition 9:50
This is the video I've always wished someone would make. Thank you!
you're welcome, and thx for the comment :)
Thanks so much for this. Just getting started in Unity (last time I did any REAL programming was in actionscript 3, lol) and this really helped clear my head regarding how to re-use and organize code intelligently. Unity is in many ways pretty similar to the flash IDE actually. Learning to move AWAY from such heavy inheritance that I was being taught back in the day is refreshing.
As always - perfect video for learning Unity and coding. Thank You for Your hard work!
Really appreciating your Clean Software Design topics! Composition is a very powerful feature of the Unity Engine. It is a style of ObjectOrientedProgramming that was passed over by most of the mainstream systems. I recall touting it back in 80s for modeling/animation software but not finding good support in languages, etc.
Great talk. The proper way to use ECS archtecture is definately via Composition. You explained the concept really really well, i would love to see you talk more about SwArchtecture in Unity, subscribed.
It's been a while since I wrote this, but this method worked last time I tried: unity3d.college/2017/04/24/360-video-in-unity-5-6/
One of your most helpful videos for me. Thank you very much!
What about interfaces vs composition in the context of Unity?
I have a fobia of writing spagetti code, so your tutorial really helped) Thanks a lot
This is awesome!!! I'm a C# newbie and found this to be a very valuable high-level explanation of how to think about setting up game code. Thank you for making this!
Time to go make a bunch of "behavior legos" and build cool things out of them. : D
This vid just changed my life. Ty you are doing gods work.
Your videos are amazing. Your professional knowledge is so rare on RUclips, and super helpful! Keep it up
just found your channel and i really like the way you approach teaching. Good to find videos more on the design philosophy!
on 11:30 it should be a RequireComponent inside the CharacterMovement class, because its the one that needs PlayerInput, the latter does not need CharacterMovement to work.
yay good video on composition and inheritance with some solid examples!! thank u :D
You can make inheritance follow the solid principles easily if you segregate well. Eg NPC should never have a 'combat' functionality by default since it is supposed to describe a plain living entity, which doesn't necessarily have to be able to fight. If you use OOP and inheritance correctly you will only project the functionality on the classes, that reflect their most basic 'actual form'
As an Unreal Engine programmer it was interesting video, i've received some decent ideas about architecture in general bc im a noob :D. It was really interesting and helpful, thanks
I really liked this video, specially at this time, I have been stuck in a project which is a mess. And we need to add a multiplayer mode in it. I think some refactoring would help. Thanks for these videos It helps alot.
great video! gonna use composition to start cleaning up my 1000 line classes!
Your tutorials are really helpful, thank you very much Jason
holy shit.... this is exactly what i was looking for!!! makes some things so much clearer
Превосходный контент! Обожаю смотреть ваши материалы!
Thanks for the video sir. 😀👍🏻
It helps me alot. Thank you, Jason
So incredibly helpfull and important information, thank you!
I was always stuggling how to put things together and I was searching ALOT for this kind of info. This should go into the Unity Coding series!! You learn all sorts of things about what is what, syntax and so on, but a more distant overview about projects, coding in general was missing badly.
One thing I'm still missing is the actual input when coding, like shortcuts, comment things out quick, how did you changed the first letter so quick, how to implement a method part when you wrot just the methods call in update and much more. Would mucho appreciate a tutorial or just tell your favorite shortcuts/techniques.
Anyway, keep it up! Good stuff! Greetings from Germany
I like your videos! Will you continue this playlist by teaching us Design Patterns applied to Unity game programming? I mean not only classical Singleton, Object Pooling and State Machine, but also others like Factory, Adapter ect.?
Definitely!
Guilty as charged. I've worked on my game for a year(on and off). Nearly finished the base game, but realized that the gameplay design was wrong and the complexity of large pieces of codes made me want to push my fingers into my eyes. So I've stopped. Now I've finally redesigned the gameplay after months and all I needed was this. Thanks. I'll start cutting up my code into little pieces.
its beautiful.
Thanks for this tutorial - really helpful
Really useful thank you, how do you decide when you should use a component for health or use an interface that "forces" a class to have hp if that makes sense?
Very useful! You help a lot, thanks!
Thank you so much for this video ! :D
By the 12:50 you talk about events...
It can be used that idea in a multiplayer project?
Like, classes inheritance and events?
If so, do you have something like that more specific?
hi would it be possible for you to show us how to create a boxing 12 round system with cut scenes between rounds please .
Thanks for another brilliant video. I wish I had the money to do your courses, they're sadly out of my price range, but I'm very grateful that you give so much of your expertise for free on RUclips :)
Can I ask... with composition is there a way to know or enforce the order in which the various components are acted on? Does the order in the Inspector make any difference? I know about Script Execution Order Settings but I can see this getting very convoluted on a large project with multiple scenes. I guess there's also the option of choosing carefully between initialising things in Awake() or Start(). Just wondered if you had any tricks or recommendations for this?
I tend to use a combo of both.
could you make a video talking on how to manage packets? great videos btw :)
I wish I can see you work on a like full project maybe something small with solid principles.
I'll definitely have to do that sometime soon
Very interesting--Thank You!
I feel one of the mein backdraws of being able to use inheritance well in Unity is their totally sucky default serializer.
Thanks for this :) Very useful!
Awesome tips thanks
What keyboard are you using?
.......Damn.......this.......is.......A.......Good.......Video.......
Hey, I am curious, would you prefer a public static event OnDied in the health class or having the pooling system actually have a reference to health Component?
that moment when you realize you've been using composition the whole time xD
You are the B E S T ! With dark mode it might be even better 🤣
Would I be correct in saying that the proper syntax today for on died would be OnDied?.Invoke();
I've a doubt.. If I have a script that manages weapon firing... If I have a weapon that fire 1 bullet once and another that fire 3 with different angulation.. Is better to do a inheritance (do another script that change the base class), or composition, so i do one script for firing like the first case, another for the second?
I also want to do a system where there are some weapons that need charging before firing the first bullet (like a minigun) and others not.. In your opinion is better composition or inheritance? (Sorry for stupids questions)
(For the last questiob)
I want to do composition but I don't know how to do that if there is the component, before firing, the weapon need to wait.. Should I use event (I can't use them)?
@@sconosciutosconosciuto2196 Ever seen that video called, "Ability System with ScriptableObjects"? You should consider adding methods to a 'Bullet' ScriptableObject that your weapon can use. Then, make an SO that inherits from Bullet, call it something like 'SplitBullet', give it a different Fire() method, and you're good.
I've always felt like the unity component system was screaming for composition and make it extremely easy to manage !
The only time I dealt a lot with inheritance was for my rpg equipment/inventory system and it was much more complicated...
Nice, thanks for all these tutorials! Can you create a tutorial on a bubble burst games? Like when you click on the bubble, it pops. I'm trying to do this, but can't figure out how to switch back from a bubble image --> popped image with the prefabs and animations I've created.
Can you maybe start a series of making a RPG game - you know because of the complexity of how most classical RPG's work (but not as complex as an MMO) and also make it 2D for simplicity sake - The point being is - you are full with knowledge and if we would have such a series, we would learn first hand from you design patterns, best practices, real life solutions in specific scenarios.. damn make it on udemy if you like - shut up and just take my money (I am kidding - don't shut up keep it comming) :)!
I'm composing a lot of scripts in my current project by having a Manager class that decides when to use which script: for example disabling and enabling different camera or movement scripts.
Do you think this is a good method or inefficient somehow?
one step further is using scriptable objects for adding functionality to gameobjects. maybe you should talk about it sometime?
Registration is showing closed on the linked course, FYI
Thanks for letting me know, just fixed the link :)
Thats great thanks! Ill go with composition from now on, it seems much easier to write and also to maintain!! Just a question after using the composition Health class, how do you access its TakeDamage() method from another class? Would it be the same thing as inheritance? ie. you have to first find the object by tag and then use "npc = GetComponent" and then use "npc.takeDamage" ?? or is there another better way to do it? thanks
FindTypeOfObject()???? He offered some reference to catch GameObject
You can use an interface in the Health class and receive hits from enemies by accessing the class, regardless of who it is, the Observer pattern will be executed
This feels like a personal attack tbh
Very nice tutorial. It just seems weird to inherit from monobehaviour when a class doesn't need its functionality, like in your health class. Maybe I'm thinking about it wrong...
happy times
Muchas gracias..!!..excelente..!!
isnt this really similar to single responsibility principle or am i missing something? sry i suck at codin stuff
Why did you have to call base. Update()? I thought the override keyword was supposed to let you have different "Update()"s from the base class.
it does, but there may be common stuff in the base class you want to call as well. One of the problems is knowing when this is a must to not break stuff or not.
so, if you call base.Update(), it will call whatever is in the base class Update, but if you just call the override Update(), with custom functions, it will do the custom functions?
You da man!
thank u sir
9:00 In fact, let's umm, watch all the movies you want for one low price.
This is like the ECS.
@7:55 this is me...
I never really liked Inheritance, while on the other hand, Composition immediately clicked with me!
more messy and less performance by far for cross calls
I'm the opposite, I prefer inheritance. Clear line of hierarchy with classes. You don't end up mixing and matching making it much easier to follow the code.
@@Scottx125Productions I'm in the same boat as you. Inheritance just makes more sense to me. But I'm finding that it has problems when we don't know the full scope of our application from the start, which can lead to a great deal of refactoring. It seems easier to follow single-responsibility when using components, so I'm starting to like components more. It does seem that Unity prefers this approach, as well, but it's difficult for me to switch my brain over from inheritance to composition.
But you can use Composition and Inheritance together.
I think what annoys me about the whole component system is that in your example and many others, these components still depend on one another. CharacterMovement still needs the NavMeshAgent and is useless without it. This is not a criticism of your design, but rather this idea that "you can mix and match components and it just works" but you really cannot in many cases because they usually need to communicate in some way.
I understood a thing after this.....
My code really sucks
I love your videos but the OnDied event name is horrible :) Event names should be Verb-ed only, like Died, Closed, Shown. OnXXX format is used for override(virtual) methods only :)
- starts showing an inheritance design
- continues to mess up the inheritance design
- points out that inheritance doesn't work well
Lol, if you want to have a Merchant in your design it should not inherit directly from your NPC class. Inside the NPC class you have some combat logic, not all NPC's do combat. Instead you should have a CombatNPC class that inherits from the NPC and put the combat logic there. This way, the Merchant could inherit from the NPC correctly with no problem at all.
Until you want to add a special merchant that can do combat. Then you're fucked
So inheritance is useless
Not at all.
The composition approach looks too heavy - 3 components on each character instead of 1 is a fuck up.
Using unity components is only one approach to composition. You could also just use class composition instead to separate concerns.