Humble Object - Game Programming Patterns in Unity & C# (kinda :)

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 87

  • @HellfireRampage
    @HellfireRampage 6 лет назад +78

    Thank you Santa

  • @RossYlitalo
    @RossYlitalo 5 лет назад +2

    I have developed a habit of looking for content by you every day now. Gotta wash dishes? First put a Unity3d College lesson running--really helps the time pass! Thank you once again!

  • @krzysztofczoczynski419
    @krzysztofczoczynski419 4 года назад +33

    Not only you've got a beard like Carl Marx, but you're also talking about classes and unity

    • @seppukun208
      @seppukun208 4 года назад +4

      Except he's not a fucking commie and marxism just destroys society

    • @QvsTheWorld
      @QvsTheWorld 3 года назад

      Good one sir 👏👏👏👏

    • @n8dev
      @n8dev 3 года назад

      LOL

    • @aeliusdawn
      @aeliusdawn 3 года назад +4

      @@seppukun208 daddy chill

    • @LautaroArino
      @LautaroArino 3 года назад +2

      Aha haha loved this one. My girlfriend just pointed out he looks a bit like a younger Slavoj Szcizek

  • @TheKr0ckeR
    @TheKr0ckeR 2 года назад

    Nowadays, I was trying to split things from Mono-behaviour and couldnt name it. Now I can its humble object pattern & poco!

  • @ZoidbergForPresident
    @ZoidbergForPresident 6 лет назад +18

    So, basically keep the data in the MonoBehaviour and then put the (testable) methods in a deferred outside class ? Using an interface to allow light testable versions of the classes?

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад +4

      yep! :)

    • @gazoonman
      @gazoonman 4 года назад +4

      @@Unity3dCollege But I still don't get it. So, should we separate all methods that we want to do Unit Test for it, and what is the real cause we have to keep it separated from a class that inherits monobehaviour? You said that it is really hard to setup, so should we avoid it? Or is there any case that we should test with monobehaviour?

    • @mistrzowieFutbolu
      @mistrzowieFutbolu 3 года назад

      ​@@gazoonman yeah, I would like to hear the answer too. I am not 100% convinced to this approach. In my opinion, in the bigger project, it could be a bit overwhelming. I will give it a try with instantiating monoBehaviour in the tests class.

  • @gabrielkind2970
    @gabrielkind2970 3 года назад

    Brilliant. Thanks Jason-- as a 10 year industrial/purist software engineer getting into game dev for the first time, I can really appreciate that someone is putting these powerful design patterns/separation of concerns into context for us. It's easy to skip when you're making a simple tiny game, but I want to put in best practices early so that my habits will support more expansive architecture and this was exactly what I'm looking for.

    • @mishapavlov1176
      @mishapavlov1176 Год назад

      Ш3н5к6😊😅😅😅😅😢😢😮😮❤😮😅

    • @mishapavlov1176
      @mishapavlov1176 Год назад

      Щ😊😅😮лондонский щкг98ш 😊

  • @VgManiac
    @VgManiac 6 лет назад +2

    I'll have to keep this pattern in mind if I'm going to use Unit testing in my game. Unit testing is actually very new to me.

  • @nitindhami2319
    @nitindhami2319 5 лет назад +2

    Hey Man! we need more of these on your channel.

  • @bloodlinegaming9962
    @bloodlinegaming9962 2 года назад

    for anyone that is just wanting to know how to clamp camera to the screen look into something like this because you wont need to call anything when it reaches the edge math.clamp(int clampNumber, int a, int b); (you may want to not do this though if you need to call on the cameras position later to see if its out of frame, you would just be adding extra calls when you could just simply set a value here to call like he did :-) )

  • @MinhNguyen-kb1ps
    @MinhNguyen-kb1ps 4 года назад

    nice pattern and also a very nice example for dependency inversion

  • @monnef
    @monnef 5 лет назад +3

    Great beard man 👍.
    Got back to Unity, currently writing a prototype of a dungeon/level generator in my spare time. Not sure if/how I should test it, since it is pretty tight with all the transforms (using position, rotation), various components ("connector" in rooms, room, room template) and GameObject (uses Instantiate), it also runs via coroutines (I need physics up-to-date so I can check collisions of rooms/halls). I guess total rewrite to not using physics (so no coroutines required) would be best approach, but I am a bit scared of that. Even thought it's not long (like 100-200 LoC), it's pretty complex.
    It might be a nice topic for a vid: "How to test code with coroutines".

  • @Sylfa
    @Sylfa 6 лет назад +3

    Looks like your close to the MVP pattern.
    BirdSplit - BirdView
    IBird ~ BirdModel
    BirdController ~ BirdPresenter
    Kinda interesting take on it

  • @KonradGM
    @KonradGM 2 года назад

    curious, how can we utilize humble objects when we are dealing with more MonoBehavior dependant methods and functions? Such as let's say RigidBody.AddForce or CharacterController.Move?

    • @TheKr0ckeR
      @TheKr0ckeR 2 года назад +1

      You would just give reference in constructor, and pass it on mono behaviour

  • @Space_Masters
    @Space_Masters 6 лет назад +10

    Loving the beard!

  • @Pedro5antos_
    @Pedro5antos_ 6 лет назад +1

    I got really interested in NSubstitute, I'm gonna search about it. But if you think it's something worth making a video about, we would really appreciate. Unit testing is something that I'm trying to apply to my projects. Thanks Jason

    • @vitalypopuzin9473
      @vitalypopuzin9473 6 лет назад

      Yeah, video on NSubstitute!!! Please, Santa, make it for us )

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад +1

      definitely will do this asap :)

  • @RobertBrunhage
    @RobertBrunhage 5 лет назад

    When you created your test in the Editor folder, how do I go about creating a folder for my tests? Let's say I want to create a folder for all my PlayerTests and then a Folder for all my EnemyTests. Then I get the reference problem for the scripts again. Any ideas on how to resolve this?

  • @MarushiaDark316
    @MarushiaDark316 2 года назад

    What's the purpose of doing Unit Tests, as opposed to simply hitting Play and actually play-testing my game with specific things in mind that I'm looking for?

  • @sven-erikjonsson3552
    @sven-erikjonsson3552 4 года назад

    The BirdController could do with some immutability (mark unchanging private fields w readonly).

  • @My_Big_Dragon
    @My_Big_Dragon 6 лет назад

    Would you please make a video about frames and how can we do animation within those frame like many VR drawing tools.

  • @DxBALLxD
    @DxBALLxD 4 года назад

    I think I spaced out.. but did we see the interface code? Is it just blank? Like, it's just a way to "tag" classes so they can slot into the code's parameter?
    Tangent but.. I'm having hard time understanding all the implications of Interfaces, so far in Unity, using them as blank addon-tags for this very purpose is about all I know.
    All and all when it comes to game development I don't get inheritance in terms of design choice. Having a base class and building everything else out of that? I find it so backwards. How are you supposed to customize freely compatible components with such restrictions? Doesn't it lead to infinite violations of DRY? Meanwhile Interfaces seem to be exactly like some sort of component, just add it, remove it, however you like. It's flipping the branching-design on it's head isn't it? You have loose bits that converge into the item you meant to create?
    Coding is confusing

  • @SirRelith
    @SirRelith 6 лет назад +1

    Love the intro. Very cool!

  • @SunnyApples
    @SunnyApples 6 лет назад

    Thanks a ton Jason! I didn't know about this pattern.

  • @mad_man_86
    @mad_man_86 4 года назад +1

    Good thing you're teaching them kids about bird-control!

  • @CoReeYe
    @CoReeYe 6 лет назад +1

    Many thanks for this! Until now I was coding a lot into the MonoBehaviors, but I will not anymore :)

  • @RaidenHeaven
    @RaidenHeaven 4 года назад

    So... using the [Test] you are are telling Unity if you insert those values the outcome should be the Assert one.
    Correct? But.. what about when things interact with other things? Like two Rigidbodies interact.

  • @LucianoPinheiro78
    @LucianoPinheiro78 Год назад

    I just fell here from the clouds. Which IDE is this?

  • @gribovmax
    @gribovmax 5 лет назад +2

    You have a cycle reference in your code. The BirdSplit holds reference to the BirdController, and the BirdController holds reference to the BirdSplit object. It may lead to memory leaks.

    • @ValeriCFBG
      @ValeriCFBG 2 года назад

      In which situations? The garbage collector can handle circular dependencies. It will just check whether something points to the Bird BirdController circular dependency and if not it will dump both of them.

  • @dago6410
    @dago6410 6 лет назад +20

    Instead of MockBird it sohould be called MockingBird (badum-ts)

  • @brainovergames7790
    @brainovergames7790 6 лет назад

    How to get all codes of your videos. Please mention links for the codes too.

  • @pythooonuser2233
    @pythooonuser2233 6 лет назад

    Very useful pattern!

  • @woti1986
    @woti1986 4 года назад

    That what I was looking for thank you

  • @HoshoLegacy
    @HoshoLegacy 6 лет назад +2

    Sorry, i apparently lack imagination. Can you give a real world example of when this would be useful? My brain can't get past the whole "just write clamp and be done" thing because the example is so simple. When was the last time you used it? What made it the best solution for that case? Thanks!

    • @Sylfa
      @Sylfa 6 лет назад +2

      About 10 years ago I was working solo on a .NET application + website. Out of curiosity I checked how many .cs lines I had (comments and Xaml generated code included) and it was around 300 000 lines of code.
      Easy enough code, but forget something or make a typo and the company would be losing money. So I made the project using MVP, which is slightly different but similar in intent, I had unit tests covering all the business logic.
      By having tests covering the code I could continue and confidently change this behemoth of a program to fit new requirements without risking my job. If I screwed something up the unit test would chime in and let me know in seconds that I broke functionality.

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад +1

      This is the biggest benefit. It removes the fear, by giving you instant feedback about the status of your project. And for the fearless, it adds some safety :) Just the last week my unit tests have saved me from breaking things 3 times (doing some refactoring and big system changes)

  • @scarneck180
    @scarneck180 6 лет назад

    Didn't really know this was a pattern but have used it and seen it used. Probably not often enough, though.
    The one thing I strongly dislike about interfaces is it's super annoying to follow when you're chasing references in code. Especially when you do have more than one class implementing it. Visual studio at least is better than MonoDevelop in that, because "Find References" on a member whose type is the interface, does indeed show the references of the classes that implement it and not just the interface itself. But while following references, I have to jump between the code and the references window instead of just hitting F12.

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад

      I've been using rider for a few weeks now (not in videos yet though), and it seems a bit better at this. Definitely recommend giving it a try, it's my main editor now. Just waiting to get a bit better at it before I do a video on it :)

    • @scarneck180
      @scarneck180 6 лет назад

      Hmm. $139 a year? I think I'll stick to the free VS 2017 for now...

    • @TheKr0ckeR
      @TheKr0ckeR 2 года назад

      @@scarneck180 coming from 2022, its worth.

  • @takashy87
    @takashy87 5 лет назад

    Interesting video, though is there any specific reason why MonoBehaviour are difficult to test ?
    (I've not written any Tests for my Unity projects yet, so perhaps this is a obvious one to people who have done so..?)
    The reason why I'm wondering is because you could still have some logic left inside the MonoBehaviour file despite trying to keep things outside of it in Controllers / etc (especially on larger projects, where it might be obvious to you that Mono files shouldn't contain any logic, it might not be very clear to others, who might introduce some logic, without knowing that better...)
    Meaning that it would still be good to test those Mono files anyway, no ?
    Mainly just curious if the reason for those "Humble Objects" is that there's something preventing testing with Mono files or why exactly trying to do this would be better than keeping things inside Mono files ? (sorry if it's a silly question)

  • @s.ahmadparkhid3057
    @s.ahmadparkhid3057 4 года назад

    Good video tutorial. I have implemented something like this but I didn't sure that my implantation is correct until I see this nice tutorial.
    I'm thinking that BirdPresenter is the correct name and BirdController can be invalid name.
    Anyway, thanks alot.

  • @CapalOnLive
    @CapalOnLive 6 лет назад +3

    @0:10 i see god. but for unity ^^

  • @htetwaiyanaung2493
    @htetwaiyanaung2493 6 лет назад

    Can you let us have the source code please?

  • @VRGameDev
    @VRGameDev 6 лет назад

    You forgot to multiply Time.deltaTime to the position update. Movement is always better if it's framerate independent :)

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад

      here I just wanted it to go up really fast, woulda just multiplied it back out by something large to make it go quick again :) (but in any real situation you're 100% right)

    • @VRGameDev
      @VRGameDev 6 лет назад

      @@Unity3dCollege Yes I think it's not a big issue, just want to prevent the newbies forgetting it :)

  • @saminanan9591
    @saminanan9591 5 лет назад

    Love the tardis t shirt

  • @beardordie5308
    @beardordie5308 6 лет назад +1

    You know what? You may have heard this before, but all I really want to say on this one is: Beard! Bbbbbbeeeeeeaaaaaarrrrd!!!

    • @beardordie5308
      @beardordie5308 6 лет назад +1

      Jason, buddy, I am a little concerned. I am generally pretty pro-beard. That much is clear. However the state of your beard has shifted into a potential My-Wife-Left-Me phase. Is that what's going on here? We're here for you, man.

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад +1

      lol it wont obey, just keeps popping up and out. need 6 more inches there so i can braid it like an old eq1 dwarf! :)

    • @beardordie5308
      @beardordie5308 6 лет назад

      @@Unity3dCollege alright, that's a noble quest. Be safe, and don't be afraid to ask for help.

  • @mykilpee
    @mykilpee 6 лет назад +1

    I love this pattern enough to implement it in production... bye mono-use, hello raw code.

  • @philipvaninting7257
    @philipvaninting7257 5 лет назад

    Gold

  • @Электроника123-ы4н
    @Электроника123-ы4н 5 лет назад

    wow thanks

  • @halivudestevez2
    @halivudestevez2 4 года назад

    I'm just about to develop my enemy aircraft moves....

  • @soyfandev4925
    @soyfandev4925 5 лет назад

    the boss

  • @bryphi77
    @bryphi77 6 лет назад

    "MockBird" :)

  • @dreamingacacia
    @dreamingacacia 4 года назад

    it seems I'm not experienced enough to understand and apply this on my project. Some day I will.

  • @donwald3436
    @donwald3436 6 лет назад

    Patterns working around platform is code smell.

    • @Unity3dCollege
      @Unity3dCollege  6 лет назад +3

      It kinda is, but the platform has some issues that make it necessary if you want to have testable code. Of course if/when people move to raw ECS, this need goes away. Part of the issue too though is that people tend to overuse monobehaviors because it's the default script type created. Often things are monobehaviors that really have no need to be and would be better as a simple class. I do agree though, it does kinda smell :)

  • @alexanderlogunov5147
    @alexanderlogunov5147 6 лет назад

    Wow, such huge beard since my last visit!
    Love this channel, but have no time to watch youtube everytime :(

  • @thedavinci1414
    @thedavinci1414 4 года назад

    I like your beard ;)

  • @AceLikesGhosts
    @AceLikesGhosts 6 лет назад

    when these vids take 100000 years to record and there only 5mins long
    Me: RRRRRRRRRRRRRRRRRRRRRREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE