You still don't use C# Interfaces? YOU SHOULD! | Practical Unity Tutorials

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ค. 2024
  • I didn't use C# Interfaces for a very long time as I never saw value in them. But then one day I had to implement an interaction system and Interfaces were the answer I was looking for.
    I will teach you Unity 1 on 1 www.tomiczengineering.com/men...
    Twitter: / darkoto56635877
    Discord: / discord
    Github: github.com/tomicz
    What are interfaces (0:30)
    Interfaces implementation (bad example) (1:29)
    Interfaces implementation (good example) (3:46)
    Bad example visualized (5:42)
    Join Discord community (10:04)
    #Unity #practical #tutorials #programmer #csharp #unity3d #you #still #dont #use #interfaces #interface #should #darko #tomic

ความคิดเห็น • 74

  • @tomiczdarko
    @tomiczdarko  ปีที่แล้ว +4

    Join our Discord community and get the best Unity tiips for free! : discord.gg/4CqnGESuRn And don't forget to subscribe!

  • @user-cu4wm5jl4z
    @user-cu4wm5jl4z 25 วันที่ผ่านมา +1

    Every time I see this guy's video preview. I'm afraid if I refuse to learn C#, he'll find me with his mafia friends

    • @tomiczdarko
      @tomiczdarko  22 วันที่ผ่านมา +1

      Tony Soprano sends his regards 😂

  • @garethdenyer21
    @garethdenyer21 3 หลายเดือนก่อน +1

    Fantastic. Compelling use of examples, comparing good with bad code, and taking us through the calls that are being made in each scenario. Your critique of other tutorials that just talk about contracts was spot on!!

  • @GiantsOnTheHorizon
    @GiantsOnTheHorizon ปีที่แล้ว +3

    Just wanted to tell you how much I appreciate your videos!!! You’re discussing all of the things that I’ve been wondering about but, like you said, are glossed over in an unhelpful and general way in other tutorials. The context and explanations you provide makes me feel like I’m a much shorter distance from becoming a strong programmer than I used to think. Thanks you!!

  • @RazixStyle
    @RazixStyle 2 หลายเดือนก่อน +1

    I have never subscriped faster to a TH-camr in my life.

    • @tomiczdarko
      @tomiczdarko  2 หลายเดือนก่อน

      Welcome! 😘

  • @Thund3rboltGaming
    @Thund3rboltGaming ปีที่แล้ว +2

    Was scrolling on youtube and saw your video about "You Are Using Update Loop Wrong" and found it really useful then i right away watched all your other videos and i must admit your videos are on next level. Your videos make people think different. I have bought myself different udemy courses and seems to me that all teach some basic stuff just like in most of those soo called youtube game devs who all show the same thing. They do not talk about data structures or what methods should we use. Most of them are even outdated and all they say oo we have 10 years or even 20 years experience in this game development. Why are there no courses from people who actually worked as game developers or have real experience. Your course sure would be on the next level. Keep up the good work !!!!

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +1

      Thank you! Your response was perfect and people like you are my target audience! I went through the same as you did and I am just sharing my experience and it seems people like it :) I will release a course, but probably next year, right now I am selling 1 on 1 consultations only for those who want more, you can check the link in the description.

  • @scevvin7788
    @scevvin7788 ปีที่แล้ว +1

    man i love the interface video with in game examples of how the programing methods interact with the game. A+. I'm very much a visual/practical example learner and this is excellent.

  • @L3GITEnt
    @L3GITEnt ปีที่แล้ว +2

    Your videos have really been helping me be able to write my own Code and make my Programs work exactly how I pictured them. Once I gained the basic understandings of how the Syntax/Keywords/OOP Principles of C# worked, it was a long journey of learning how to use some of the more "Intermediate" levels of making Code run. Videos like these have been a big help in making the Science behind Programming much easier to grasp! Now I see exactly what I was missing when trying to learn how to use Interfaces in Unity. Thank you!

  • @kevin41307
    @kevin41307 9 หลายเดือนก่อน +1

    very practical tutorial, thanks a lot. please make more~

  • @Braanflakes
    @Braanflakes ปีที่แล้ว +1

    My friend, I can’t thank you enough for this video. I’ve been struggling with interfaces for a while now and you explained it in a way that I could actually understand. The Diablo references really helped to nail the concept down. Much appreciated!

  • @richie4956
    @richie4956 6 หลายเดือนก่อน +1

    THIS ONE MAKES SENSE. WHY CAN'T ALL TUTORIALS BE LIKE THIS

  • @LuRybz
    @LuRybz ปีที่แล้ว +1

    this is the perfect practical example for Interfaces.
    Another level of complexity would be to add different states to an Interactable, for example a Door that can be opened, closed, locked, etc...
    And another level would be to handle multiple different Interactions for the same object (Grab, Open, Throw, Inspect, etc...)
    And beyond that would be to handle animations and synchronism to the actions (go to position X, find closest door, open door, etc...)

  • @regys9521
    @regys9521 7 หลายเดือนก่อน +1

    This channel deserves so much subs

  • @ImmortalTimothyM
    @ImmortalTimothyM ปีที่แล้ว +1

    Commenting mostly to help boost this video in the TH-cam algorithm, however, while I already use Interfaces, this video is so clear and actually explains why to use interfaces. You are one of the few who are making videos that actually lead people out of tutorial hell.

  • @TheNjordy
    @TheNjordy 7 หลายเดือนก่อน +1

    Baron Zemo made the best tutorial on Interfaces. Such a good deed would justifies even wiping the Avengers out :)

  • @audreyjensen666
    @audreyjensen666 ปีที่แล้ว +1

    Gold video, thanks.

  • @MySandy9
    @MySandy9 3 หลายเดือนก่อน +1

    Haha it's just a contract very true , love your explanation with examples.

  • @luchinazo
    @luchinazo ปีที่แล้ว +1

    Many thanks, I've been programming for the past 10 years but coding games is a different kind of beast.

  • @kmw9031
    @kmw9031 2 หลายเดือนก่อน +1

    Looked into interfaces a bit and initially dismissed them after misunderstanding what the benefit of using them is supposed to be - wanted to confirm whether my dismissal was the right choice, and came across this video
    And what a well made video this is! Great example and explanation, which helped me see the actual benefit with regards to scalability. Huge thank you!

    • @tomiczdarko
      @tomiczdarko  2 หลายเดือนก่อน +1

      Thank you!

  • @yunsaymontila5168
    @yunsaymontila5168 2 หลายเดือนก่อน +1

    Very good video

  • @_ssox
    @_ssox ปีที่แล้ว +4

    Wait... This is actually a great video! Cheers for this, man. Your videos are unmatched in comparison to other TH-cam Unity tutorials.

  • @DBarnes07
    @DBarnes07 25 วันที่ผ่านมา

    Great video, really helped visualize how interfaces could be useful. Only suggestion would be to show the correct method first, as showing the incorrect method first can actually reinforce that. And also showing the full methods from start to finish, instead of doing first half bad, first half good, second half bad, second half good. This made it a little confusing cus they got jumbled together in my brain. Was able to skip around tho to achieve this and everything was much easier to understand and u made it all make sense. Thanks again for the great video tho, earned yourself a sub

  • @rafacode1
    @rafacode1 ปีที่แล้ว +1

    That was a very clear video explaining interfaces, thanks a lot!

  • @genie52
    @genie52 ปีที่แล้ว +1

    go Darkoni!

  • @unityvictor787
    @unityvictor787 ปีที่แล้ว +1

    Nice Tutorial, easy to understand.

  • @jelliottmason
    @jelliottmason ปีที่แล้ว +1

    Best video I've seen explaining interfaces.

  • @yogeshrawat7140
    @yogeshrawat7140 ปีที่แล้ว +1

    Wow 😳

  • @Johan-rm6ec
    @Johan-rm6ec 6 หลายเดือนก่อน +1

    Late to the party but a good video. That whole contract thing sounds like nonsence. I learned Assembler coding by myself in the 80 - 90ties. Why is it that C# is so overly complicated explained? Love this channel by the way.

  • @ANGELB3AR
    @ANGELB3AR ปีที่แล้ว +1

    Mmm yes. You’ve earned my subscription my good sir

  • @abdullah4653
    @abdullah4653 2 หลายเดือนก่อน

    well explained

  • @thehyper4288
    @thehyper4288 ปีที่แล้ว +1

    Super helpful, thank you

  • @TheKr0ckeR
    @TheKr0ckeR ปีที่แล้ว +2

    Thanks. I want to ask more deep question about that. I had some experiences that interactables needs bunch of parameters. For example a loot crate is needed our inventory to call addToInventory etc. I mean a lot of interactable needs different parameters but since this method has no parameter, its not helping to the OOP and dependency coupling. I've managed to create an InteractParams class to pass everything interactables needed but in short time class itself made a mass variables that is not related to each other (PlayerInventory reference, Transform reference, etc.). How would you approach to that?
    Shorter question:
    How you would you approach to the problem where interactable needs parameters (every interactable needs different params like player's inventory, or some other info.)

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว

      The idea behind the video is to explain what interfaces are, I couldn't possibly cover every possible edge case. Your question is too complex to explain over youtube comments, but I will give you directions that you can explore and test it yourself. Contact me over discord and we can go over your code.

    • @TheKr0ckeR
      @TheKr0ckeR ปีที่แล้ว +1

      @@tomiczdarko Of course. Thanks a lot. I didnt mean your solution was not helping, My solution wasnt helping me. :)

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว

      @@TheKr0ckeR No worries :)

  • @bloodsample2893
    @bloodsample2893 17 วันที่ผ่านมา

    Thank You Think

  • @GlasTaibhse
    @GlasTaibhse ปีที่แล้ว +1

    great vid!!! can you do a video of c# events and event listener? they don't make sense to me

  • @omelette2718
    @omelette2718 ปีที่แล้ว +1

    Really cool videos, I feel I'm reaching the end of "bad tutorials and I was just writing what the youtuber was writing" and reaching to more advanced understanding of Game Dev.
    Could you just lower the sound of the music during your videos? It's kinda hard to focus sufficiently on advanced topics with noise in the background!
    Thanks a lot for the tutorials ! Leaving a comment here before the channel blows up !
    OP7

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว

      Thank you! Notes Taken!

  • @glimpsygames2734
    @glimpsygames2734 ปีที่แล้ว +1

    Great, keep posting videos, I even wanna make professional tutorials but youtube almost hid my channel I don't know why

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +1

      Thanks! I recommend that you go onto reddit.com/r/newtubers and learn from experienced youtubers on how to grow on youtube. I do it myself.

    • @glimpsygames2734
      @glimpsygames2734 ปีที่แล้ว +1

      @@tomiczdarko Thanks a lot, I will try that

  • @AndersenCastaneda
    @AndersenCastaneda ปีที่แล้ว +4

    An interesting explanation for a junior in programming, but the final code isn't quite right. You should create an InteractionComponent, the logic shouldn't be in the player class, only the reference to the component. Components (data) and Systems (logic) should be testable independently, and in this way, you can run your systems in a predictive order (one Update() to handle all systems). This style is simpler to understand and is used by the top companies in the game industry.

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +2

      I do agree. I had to keep it simple for simplicity. I have to focus on the concept of interfaces and not on overall abstraction.

  • @osmanerenkose6692
    @osmanerenkose6692 ปีที่แล้ว +2

    First like

  • @yudnai5577
    @yudnai5577 หลายเดือนก่อน

    cool video. the music is a little loud.

  • @heman922
    @heman922 ปีที่แล้ว +1

    Plz do a video about unity dots 1.0 version that recently released ❤️

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +1

      I wont be focusing on dots and ecs on my channel, we are more of a general programming channel. Turbo Makes Games has a channel that is focused on dots and ecs, its worth checking it out.

  • @emmanuelgonzalezcaseira9141
    @emmanuelgonzalezcaseira9141 ปีที่แล้ว +1

    8:55 I do have a question, hope you can clarify me this: How does the code know that GetComponent gets IInteractable from the Door class? seeing how many classes have the IInteractable interface component, how does it know which one does get? why it doesn't get, for example, the component from the Portal or Blacksmith class?

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว

      It gets the one that the player enters into the proximity. It knows that it's the door, because player is inside Door's OnTriggerEnter() collider. If player goes to the Portal and enters its collider it will get the one from the portal. Let me know if it is clear enough?

    • @emmanuelgonzalezcaseira9141
      @emmanuelgonzalezcaseira9141 ปีที่แล้ว +2

      @@tomiczdarko Hmm... I see, I see. I guess I didn't get it fully since I didn't saw the complete example of the code, so thanks for clarifying it for me. Thank you for answering me. Yes, it is clear enough.

  • @Fathomorg
    @Fathomorg 4 หลายเดือนก่อน +1

    "Thank you think"

  • @TheFlintMontana
    @TheFlintMontana 7 หลายเดือนก่อน

    Solid tutorial, but i'm still having trouble understanding how the collider knows it's dealing with a door. It looks like to me if you had both a door and chest object within the same collider vacinity - innheriting from iinteractable -- you would trigger both objects at once? You would still need a door check somewhere in this case? or am i missing something?

    • @THEspindoctor84
      @THEspindoctor84 6 หลายเดือนก่อน +1

      The collider doesn't know that it's interacting with a door, it only knows that it's interacting with something that it is interactable - thats the beauty of it!
      As far as two IInteractable things next to eachother - yes, you would need some logic to block the second one if an IInteractable is already in range.

    • @TheFlintMontana
      @TheFlintMontana 6 หลายเดือนก่อน

      lovely mate, thought so, thanks for the extra explanation.@@THEspindoctor84

  • @christians.4183
    @christians.4183 2 หลายเดือนก่อน +1

    Video is good, thumbs up but the mouse? Seriously?

  • @CHEEZEyCHEEZE
    @CHEEZEyCHEEZE ปีที่แล้ว +1

    A lot of people say "GetComponent" is a bad thing to call?

    • @holmbergen
      @holmbergen ปีที่แล้ว +2

      It depends on context of where it's used. If it's used in Update() then it's very bad, you usually want to cache it in Awake() or Start(). But there's another function that Unity recommends which is better for performance I believe (haven't tested it myself). That function is TryGetComponent(out T var)

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +1

      @@holmbergen Good answer!

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว +1

      As Patrik said, it depends on the context. In this case it's fine, because we can't cache an object at awake because we don't know with which object we are going to interact with, so we have to use GetComponent. Also, it's done in only one frame and one call so it wont affect the game at all, it's completely safe. Watch my "You are using an update loop wrong" video and it will make more sense to you.

    • @CHEEZEyCHEEZE
      @CHEEZEyCHEEZE ปีที่แล้ว

      ​@@tomiczdarko But you are calling .GetComponent() whenever an agent goes up to an interactable object. So if you have 100 Agents they would be calling .GetComponent on 100 different interactable objects. In other games they have different objects you can interact with depending on a RayCast from the center of your screen. So Call of Duty will have a pile of guns you could interact with. In some cases you have 20+ things you can interact with. It will change what is interactable by changing your position and camera placement. Sometimes it is difficult to select one thing. But that is not the point I am making about the design and difficulty of selection. I am saying that in CoD you would be making this call several times for every object you look at and walk over. I could imagine a bunch of Agents going to Work. They would have toothbrush and showers and sinks and closets and cars and food etc. So in the morning rush hour several Agents could be all calling this at the same time getting ready for work and getting in their cars. Once they are at work they could interact again with the computers at work.

  • @lee1davis1
    @lee1davis1 ปีที่แล้ว +1

    Nope. I still don't use interfaces. I use inheritance and overrides a lot though.

  • @sanctanox
    @sanctanox 8 หลายเดือนก่อน +1

    People who watch tutorial video don't want to be entertained but learn something. You video is good but the background music is annoying. I know some people use music while learning but they should choose their one music. In a tutorial video most likely people hate background music as it distracts them.

  • @ytubeanon
    @ytubeanon ปีที่แล้ว +2

    @darkotomic9501 I appreciate your tutorials, so I thought I'd mention when I click on the 'I will teach you Unity 1 on 1' link, it goes to an error page cuz the url has literal '/coa...' at the end instead of truncation

    • @tomiczdarko
      @tomiczdarko  ปีที่แล้ว

      Fixed it. Thanks for pointing it out :)