You need to know this! Lambda expression and Action Delegates in Unity

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

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

  • @PhiLudo
    @PhiLudo Год назад +2

    great tutorial. i love that you explain it for absolute beginners in a clear way, without expecting too much preknowledge

  • @Focto
    @Focto 7 месяцев назад +2

    Excellent tutorial i've ever seen before, doesn't like other channels that explain with many syntax that i don't know about it. But this such a perfection 👍🙏

    • @SunnyValleyStudio
      @SunnyValleyStudio  7 месяцев назад

      Glad it helped! 🙂 It isn't an easy topic to explain but I did my best to explain it as I understand it.

  • @MilchoMalefic
    @MilchoMalefic 6 месяцев назад +1

    this actually clicked thanks to you, thanks

  • @Killerbiene09
    @Killerbiene09 Год назад +1

    Excellent video on the topic - i was struggling with the new input system and how to invoke the events and your explanation really brought it home for me.

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

    Hey Peter just wanted to let you know I get so much out of your tutorials. Really like the way you explain and you cover advanced topics in a really thorough and helpful way. Thanks so much for taking the time to make all your content - wishing you all the best!

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

      Great to hear! I know how hard / boring it can be to learn about programming. I am doing my best to help others to understand it :)

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

    Wow I don't comment very often but this was one of the best tutorials I have ever seen for such a complex topic. I was having a really hard time reading through the documentation trying to understand these concepts and you put it together in such a perfect way that I feel like an expert coming out of this video. Thank you so much for your hard work, I'm sure you've helped many indie game devs such as myself in more ways that you can imagine!

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

      Thanks for watching! I think I have made the video tool long - could have done better job looking from the perspective of time. Still I'm glad it has helped you! 👍

  • @Hans-rq2ge
    @Hans-rq2ge 3 года назад +3

    Your videos are great, have wanted to get into lambda expressions for a while now.

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

      I am glad my video was helpful. I hope the explanation was ok and that you can start using the lambda expression in your code :)

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

    wat a cool video... more new things are in this video... with great explaination...

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

    this tutorial helped me so much.....
    lots of love to your work sir ❤️❤️❤️🙏

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

    Man your tutorials are so valuable keep the good work !

  • @AstralNostalgia
    @AstralNostalgia Год назад +1

    it is very good because even you put arguments in a lamda , one example with argumetns nad other without? very good

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

    Great tutorial as always

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

    This is exactly what I needed thank you so much !

  • @sdasddsasadad2287
    @sdasddsasadad2287 3 года назад +1

    Thank you! it was a great tut to learn Csharp!! 0:54

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

    awesome sir.

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

    This was helpful. To next time, can you plz just go scroll up and down so I can see the whole script att the end thx :)

  • @ltpstudio8223
    @ltpstudio8223 7 месяцев назад +1

    I think this is technically an expression-bodied member. I’m still struggling with the difference tho and i remember lambda as a term more easily

    • @SunnyValleyStudio
      @SunnyValleyStudio  7 месяцев назад

      It might be so. I'm not great with those technical terms.

  • @amac333
    @amac333 3 года назад +1

    this was helpful, thanks. I wonder, instead of passing the action, could you pass a vector3 instead so you're not using Actions/Delegates? The benefit of this is you could call it from another script?

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

      Hey!
      Delegates are meant to make the code more reusable. In OOP you generally pass Objects instead of an Action reference - I think that was your Vector3 question. You can call a method directly on another object like *Character* can call when dying *audioSource.Play()* . It works great but now you want to spawn particles as well, and later show *End game UI element* . While you can reference all those objects inside your *Character* class its much easier to have ex *UnityEvent OnDie* and assign all the methods to be called through the inspector.
      The problem that Delegates (like Action) solves is maintainability - how easy it is for you to add new features or modify existing logic in your game (and more specifically they solve the issue of "I have made my code more OOP but now how do my classes communicate with each other so that I can easily add functionality to my game").
      I hope it helps!

  • @Atulkumar-sz6tg
    @Atulkumar-sz6tg 2 года назад

    A query, we could have created a function with three params x,y,z, wouldn't it have been same as using action param in the loopthroughgrid() function?

  • @de0o0
    @de0o0 3 года назад +1

    I get the idea, but I am deeply wondering, may I missing something and I can be wrong, but using events, delegate and invoking them or using signals in zenject isnt better method?

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

      Hey!
      Zenject is great as far as I can tell and surely you can inject dependencies in multiple places this way.
      Event driven architecture is just another way to bind a method call to something. Like when your Player was hit you want to reduce health. Instead of checking in the update "Has it changed? Has it changed? ..." constantly you create an event *HealthChanged* that will inform the UI element when the health has changed.
      This way Ui doesn't have to know about the Player or the player about the UI. The connection can be created dynamically at runtime.
      Keep in mind that in Unity the *Inspector* serves us as dependency injector. It allows artists / designers to tweak the code behind the game without knowing how to code. That is why events are so important in my opinion :)

  • @Danyu91
    @Danyu91 3 года назад +1

    Question: how will you remove the anonymous function then? Thank you for the tutorial and keep it up!

    • @SunnyValleyStudio
      @SunnyValleyStudio  3 года назад +1

      Hey!
      Generally you want anonymous function only for stuff that is constant thought the scene ex Menu Button should always trigger menu visibility.
      To reset it the only way is to set your event Action *OnMenuPressed = null* but this resets all the callbacks assigned to this event.
      It is safer to use += / -= and to use a named function.

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

    value

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

    ty

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

    a slow motion version of codemonkey tutorials kk, thanks

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

      Do you mean "slow" as good?
      Yeah I guess I am sometimes creating similar content to Code Monkeys vids 🙂

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

      @@SunnyValleyStudio yes. its easy to understand.

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

    Necesito este video pero con subtitulos al español :(

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

      When you enable subtitles you can click the COG icon and turn on auto translation and select the language that you preferer 🙂

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

    Microsoft should remove the Lambda Expression in C#, its just stupid idea.