It's easy to think your code will always be UGLY!

Ойындар

Fluent Interface Design in Unity C# is a powerful design pattern that aims to make your code more readable and intuitive, allowing methods to be chained together in a fluid and expressive manner. Using the example of cloning an AnimatorController, this video will demonstrate how Fluent Interface can transform complex operations into clean, elegant one-liners, significantly reducing code duplication and enhancing maintainability.
Want to support me? 😀
Buy me a coffee! ko-fi.com/adammyhre
🔔 Subscribe for more Unity Tutorials / @git-amend
Discord: / discord
#unity3d #gamedev #indiedev
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 Fluent Interfaces
1:12 Cognitive Complexity
3:00 Refactor to Fluent Interface
14:00 Testing
Source code: gist.github.com/adammyhre/cd9...
More Useful Code:
github.com/adammyhre?tab=repo...
Unity Utility Library: github.com/adammyhre/Unity-Utils
Lock Inspector Hotkey: gist.github.com/adammyhre/475...
Assets Shown In This Video (Affiliate Links)
Procedural Progress Bar: assetstore.unity.com/packages...
Dungeon Mason Tiny Hero Duo: (FREE): assetstore.unity.com/packages...
Tiny Heroes: assetstore.unity.com/packages...
Tidal Flask Dungeon Pack: assetstore.unity.com/packages...
Hierarchy Icons: assetstore.unity.com/packages...
Better Transform: assetstore.unity.com/packages...
Better Mesh Filter: assetstore.unity.com/packages...
Kyeoms VFX: assetstore.unity.com/publishe...
Follow me!
linktr.ee/gitamend

Пікірлер: 55

  • @git-amend
    @git-amend5 күн бұрын

    Happy Sunday! I'm very interested to hear how you've been using Fluent Interface Design in your projects! Builders? Functional? Immutable or Mutable? Let me know! 👍

  • @Ironlionm4n
    @Ironlionm4n5 күн бұрын

    Even though most of these videos are beyond my skill level, I still try to pay close attention to learn any little thing I can. 1% better every day and this channel is a gold mine of knowledge!

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks for watching! A lot of people forget that professional development compounds with that daily investment. That 1% makes all the difference!

  • @JoeldaSilvaVicenteFilho
    @JoeldaSilvaVicenteFilho5 күн бұрын

    One reason I love these types of videos is that even though I do this often, I didn't even know it had a name (or I just forgot :V), so now I can look for even more info about it!! Thanks for the great work as always!!

  • @git-amend

    @git-amend

    5 күн бұрын

    I'm so glad!

  • @johnsartain4160
    @johnsartain41605 күн бұрын

    Im a senior software developer, but i didn't even know how to do that. Thanks!

  • @git-amend

    @git-amend

    5 күн бұрын

    Glad you enjoyed it!

  • @UTTheLaw
    @UTTheLaw5 күн бұрын

    Really enjoy watching your videos - I could watch you code all day, lol! ..For me, as someone new to Unity/C# just this year, most of your coding videos kinda fly over my head, but I watch and feel inspired and try to take away what I can, plus I kinda bookmark somethings so I can come back when my kung-fu increases. I think your a great fit for these more advanced coding sessions, but if you ever wanted to take it back to the beginning a little more, I'd certainly be here for that! (For example, I don't even fully understand what static methods/classes can do for me and why I should consider them. I do know what static is, I just don't always know when to and when not to use them - along with many other similar fundamental's !) ...But you're great at what you do, so perhaps it's best to stick to what you're good at - cause you are darn good! There are plenty of beginner videos out there, ofc! Thanks for all your work! Keep it up!

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks for the comment and suggestions!

  • @silchasruin4487
    @silchasruin44875 күн бұрын

    Thank you so much for keeping things going on your channel. I've come to a standstill with my own development, along with keeping up with your vids. I've been bookmarking them for when I have time to dig into some of them. Really looking forward to seeing more from you in the future!

  • @git-amend

    @git-amend

    5 күн бұрын

    You are so welcome!

  • @CyberStudios
    @CyberStudios3 күн бұрын

    Thank you for the time and effort you always put into your videos, it has helped me a lot to code better and fix a lot of bloat in my unity projects! By far the best channel that delves into coding in a whole different way! Been doing this for a long time, and very happy I can learn new things even now. I do have a request :D, would it be possible some time in the future if you could make a video that covers all the code patterns as a short understanding of what they are, and what their purpose is. I have thoroughly enjoyed learning about the different patterns and wish I had more time to delve into all of them.

  • @git-amend

    @git-amend

    3 күн бұрын

    Thanks for the comment! I don't know if I'll make one video that covers all patterns, but I do have plans to make a few videos that show how to combine patterns. And of course, there is an entire playlist about patterns you could watch one by one: kzread.info/head/PLnJJ5frTPwRMCCDVE_wFIt3WIj163Q81V

  • @ArisSemertzidis
    @ArisSemertzidis5 күн бұрын

    Love the way you are presenting these concepts. One thing that bugs me though is that when returning the component (AnimationController in this case) in a function I would think initially that returns a copy of it. But what it does is updating the target and returns it, so you can chain multiple commands. sometimes that would get me tricked if using external libraries.

  • @git-amend

    @git-amend

    5 күн бұрын

    Yes, I had considered that. Often when making a fluent builder, we keep things mutable... but a more functional style would definitely want to keep it immutable. For a method that is cloning one object into a new one that has already been created in the caller - it's hard to say which is best, and in some (other) cases there may be performance considerations. This is probably a great subject for another video.

  • @NathanSL11
    @NathanSL115 күн бұрын

    A great use case for this sort of fluent system is XR interactions, there is so much conditional setup that gets turned on or off in XR that this sort of thing really makes extending and implementing much easier.

  • @git-amend

    @git-amend

    5 күн бұрын

    Great example!

  • @jvizcode4845
    @jvizcode48455 күн бұрын

    Great! I belive Fluent Design is one of the most satisfying parts of programming. Also great for testing. I was wondering if you have any plans of making a video about multi language features in Unity. Thats a nice feature to care about this days. I have been using XMLs and adding componets to texts objects, but after watching your videos I am thinking about a sceneContext that loads everything included texts per scene, something crazy like that haha Thanks for the new perspectives. Anyways I would like to hear any tips from you Master. Thanks for the weekly video.

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks! I had not considered talking about any of the multi-language features yet, but maybe you've given me a good idea for a potential good use case. I'll give it a bit more thought!

  • @Fitz0fury
    @Fitz0fury5 күн бұрын

    the amazingness of this as a tool is almost overlooked in the video until the end, as it isn't really the purpose of the video... but the tool is sort of game changing. One Animator that can effectively be re-used regardless of the rig. that's a really nice time saver if you have a lot of rigs that usually require their own animators due to extra layers or things like wings. it also reduces the chance for human error when making all the conditions/transitions. you can still use overrides for rigs with different weapons or whatever. its a really big efficiency gain! Thanks!

  • @realtimberstalker

    @realtimberstalker

    5 күн бұрын

    This is already how animatorcontrollers work no?

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks. For me, I think the benefit is in the ability to only copy some parts and not the entire thing.

  • @Fitz0fury

    @Fitz0fury

    5 күн бұрын

    @realtimberstalker yes but cloning the animator controller doesn't allow you to select the components to ignore and such. So you can clone it and then still have to delete things or tweak things a lot. This becomes very handy with layers or blend trees. If you only have a few monster rigs it's no big deal. What I'm working on though has about 30 unique rigs. Manually handling units animator controllers is pretty tedious. Anything that reduces the need to manually change the animator controller us a pretty solid win.

  • @RafaelAzriaiev-kv9qm
    @RafaelAzriaiev-kv9qm5 күн бұрын

    Nice ill try to incorporate it in my own coding

  • @git-amend

    @git-amend

    5 күн бұрын

    Great, let me know how it goes!

  • @Soraphis91
    @Soraphis915 күн бұрын

    In general nice video. I'd still like to nitpick a bit :) 0:15 not really a fair comparison, as you'd get the same with just creating (local or nested-class) methods and calling them in order. I'd also argue that this Clone method is not even a good example for a fluid approach (creating fluid interfaces is mostly useful if you write an API that is meant to be used "often" (either by yourself or by many others) and it is supposed to make usage easier. Which (probably) does not apply to the stuff within that Clone method. Especially unfair is the comparison, if you need to ensure that the (some) methods are only allowed in a specific order (e.g. ClearParameters before CopyParameters), because then you need to return some interfaces (that also your type needs to implement, so only availble for types you own) (which becomes a terrible mess if you have optional or conditional steps in between, which makes this approach really only worth it, if it IS for an often used API). 1:10 I'd flip both if statements around with early returns. But that's personal preference 11.10 Should be "CopyDefaultState" instead of "Set" (as set would imply that you'd have a "State" argument to pass to it. Especially if you leave them all be public. probably would've been better to move them into a private-nested class "Internal" - sadly then they _cannot_ be extension methods, so you'd have to call them in a non fluid way, but better hides the helper methods.

  • @git-amend

    @git-amend

    5 күн бұрын

    All valid nitpicks I'd consider (and maybe even add myself) in a code review. Thanks for the comment!

  • @Piaasek
    @Piaasek3 күн бұрын

    Hello, I love your videos man, helped me get a good job. I am a unity developer with 6 years with experience but after lay offs I started doubting myself. Now Things are good again. One question, are planning on sharing your Rider settings? would love to see those. (reformating, clean up)

  • @git-amend

    @git-amend

    3 күн бұрын

    Thank you! Glad to hear about the job, times are challenging these days. I actually do have a setup/config video planned, and I'll be sure to include some Rider specific things.

  • @Piaasek

    @Piaasek

    3 күн бұрын

    @@git-amend Great news! I will be looking forward to it.

  • @midniteoilsoftware
    @midniteoilsoftware4 күн бұрын

    Brilliant!

  • @git-amend

    @git-amend

    4 күн бұрын

    Thank you!

  • @oldshamen
    @oldshamen4 күн бұрын

    You content keeps amazing me.

  • @git-amend

    @git-amend

    4 күн бұрын

    Thank you!

  • @Thimas
    @Thimas4 күн бұрын

    Amazing video as always! Method chaining / Fluent Builder pattern has become one of my favorite patterns after DoTween's amazing architecture showed how powerful it can be. I do wonder however. Isn't the functionality of your clone tool doing the same that Unity's built-in Animator Override Controller does? Your version does however allow for a much wider degree of freedom from the developer!

  • @git-amend

    @git-amend

    4 күн бұрын

    Thank you! An Animator Override Controller is generally used to swap in new animations for existing ones in an Animator Controller, whereas this tool is for copying some (or all) of the parts of an Animator Controller (states, transitions, properties and motions) into a new one.

  • @4rcant
    @4rcant5 күн бұрын

    your videos are better than therapy

  • @git-amend

    @git-amend

    5 күн бұрын

    Haha thanks!

  • @loscaballerosdebronzodia8211
    @loscaballerosdebronzodia8211Күн бұрын

    Being new to programming i wish to ask which resources do you recommend to learn c# and programming in general , you seem very knowledgeable so i wish to know

  • @git-amend

    @git-amend

    Күн бұрын

    If you join the Discord, take a look in the #programming section - there is a pinned list of recommended reading to help people progress from Beginner to Advanced

  • @edward3190
    @edward31905 күн бұрын

    could this pattern be useful to write a sequence of actions? for example, NPC.GoForward().Wait2seconds().Reload().ShootGuns()

  • @git-amend

    @git-amend

    5 күн бұрын

    Sequences are a great use case, though ones that need to wait or run a coroutine may need special consideration

  • @PixelBlight

    @PixelBlight

    3 күн бұрын

    You could use the builder pattern and your api would look basically like above and still use timers. I think amend has a video on it.

  • @SanderDecleer
    @SanderDecleer5 күн бұрын

    While I love fluent interfaces, I'm not sure if I would use it inside of a utility like that. This does not really add a lot of readability over just using regular static methods. Using them for factories or other configurations, like you mentioned, seems way more beneficial to me. There the branching options allow you to get more usage out of the extension methods. Great video with another awesome topic!

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks for the comment. Myself, I also primarily like using it for constructing other objects or configs. Maybe we can touch more on branching and extending it in a future video.

  • @SanderDecleer

    @SanderDecleer

    5 күн бұрын

    @@git-amend sure thing! It's just a matter of preference of course

  • @iliqnikushev3820
    @iliqnikushev38204 күн бұрын

    Sometimes i just wonder... Why is this not in the original library that comes with the package? I feel you need to start poking Unity, cuz stuff like this belongs there! :)

  • @git-amend

    @git-amend

    4 күн бұрын

    Haha, yeah maybe. You could say the same about custom processing of Animations, especially humanoid rigs - always requires writing some custom code.

  • @damonfedorick
    @damonfedorick5 күн бұрын

    NICE.

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks!

  • @damonfedorick

    @damonfedorick

    5 күн бұрын

    @@git-amend almost at 500,000 total views on all your videos, that's crazy. i'm still only just over 100k, your hard work is paying off.

  • @git-amend

    @git-amend

    5 күн бұрын

    Hard to believe isn’t it

  • @forbiddenbox
    @forbiddenbox5 күн бұрын

    SUNDAY

  • @git-amend

    @git-amend

    5 күн бұрын

    Thanks for watching again! Cheers!

Келесі