Revolutionize Your Unity Game with Optionals and Monads

preview_player
Показать описание
Nullable types (`int?`), the `default` keyword, and the null-forgiving operator (!) set the stage for creating powerful Monads like Optional and Either in Unity. In this video, we dive into how these Monads can eliminate null checks, handle success and failure scenarios, and simplify branching logic. With practical examples, you'll learn how to implement Optional and Either to write cleaner, safer, and more expressive code for your Unity projects.

Want to support me? 😀

#unity3d #gamedev #indiedev

▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬

0:00 Nullables and Default
4:35 Null Object Programming Pattern
5:30 Optional Monad
10:30 Either Monad

More Useful Code:

Assets Shown In This Video (Affiliate Links)

*Follow me!*
Рекомендации по теме
Комментарии
Автор

Happy Sunday! Hit the LIKE button if you learn something new today! 👍

git-amend
Автор

This is huge. I'm so glad I found your channel a while ago.

mypaxa
Автор

I'd like to add that a Monad is a monoid in the category of endofunctors

bogoid
Автор

I absolutely love your tutorials, it's like getting 1 year of experience in less than 20 minutes.
I'm very much using null values as a caveman right now as I tried using the nullables from C# with Unity but ran into all kinds of weird problems like having to have preprocessor directives all over the place and I think in the end it didn't even work so I just gave up.
Coming from JS I sorely miss the ?. syntax which I'm still not sure how much it's supported or not in C# and Unity. Like Unity objects say not to do it, though it seems to work most of the time.
These are really interesting techniques, especially getting two types out of a statically typed language in a clean way was something I always struggled with.
Keep it up man, your videos are packed with insane value

RogueWolf_Dev
Автор

Excellent presentation, and very valuable tutorials. I hope you continue making this type of content.

yoimokacc
Автор

Honestly, I've not been this excited to see a new upload since Brackeys, and I mean no disrespect towards Brackeys but I think your videos are so much more valuable and informative.

I think you should keep making these informative/introductive, more isolated video explanations and demonstrations, but have you considered also making a series of sorts, short courses which span over a few videos, utilising several of the concepts and patterns you've made videos of in the past, to show the workflow and thought-process of how to tie things together?

There's plenty of code-alongs and "how to make <game>" out there, but I think the majority of them are detrimental even. There's been so many videos, especially when I was first starting out, that just left me more confused and feeling less knowledgeable than when I first started watching them, because they would keep introducing new terms, concept and patterns without properly teaching you the tools but just followed the (totally not a term I just made up).

I honestly think your videos should even be sponsored/featured in the tutorial section of the Unity hub.

It'd definitely be more planning and effort to make a tutorial-project, so I wouldn't blame you if you feel that it's too much of an undertaking, but I do believe that it'd be amongst, if not *the* most useful and informative learning sources for Unity available. (You also have a really good voice so it's easy to stay focused and listen!)

Luciphear
Автор

It was just last week that I had to bang my head against a brick wall to make Option<T> myself lol.
nice vid.
Option<T>s are far better than they are given credit for

Cryosimorgh
Автор

Thanks for sharing another great introduction tutorial.

marlonruvalcaba
Автор

I have been thinking about this video a bit and i might actually implement it. Specifically for real time ui icons like status effects (a very similar use case to empty inventory slots).

Fitzfury
Автор

Thanks for the great video! It would be helpful to mention that these structs can also be made Serializable. With a simple drawer, they can be more transparent for users working only in the editor, while also handling null references more gracefully without throwing exceptions.

hakerlod
Автор

Java's optional was a game changer when it was introduced.

lonbpalmer
Автор

Interesting. Could this be used to implement Linq-like functionality on Native Collections within DOTS/ECS (since Linq does not work within DOTS)?

jeffreyhersh
Автор

Been programming for a while now and somehow 'monad' has slipped past me. New term, or at least, this is the first time it caught my attention! Thanks again for another great video!

ewwitsantonio
Автор

The concept of FP Monad doesn't really touch me, do you have any books to recommend?
I understood the basic concept, but I think I need an example as well.

정동우-nx
Автор

Where did you learn to code like this, are there other resources we could dive into to improve code quality?

dorzaii
Автор

Maybe I'm too much of a noob for this subject... But I didn't quite understand why to use this... Could it be to avoid nullref exceptions?

luizthiagosouza
Автор

I use languageext for fp in unity it's awesome but I had some troubles to make it work with unity

captainnoyaux
Автор

In my inventory I declare the Null item as a type of Item (learned from Zoran's videos), and store it as a static field

public record Item(int Id, ...) { public static NoItem NoItem = new(); };
public record NoItem : Item { public NoItem() : base(-1, ...) { } }

GameDevSimp
Автор

i have java background, I LOVE nullables.

shuoyuanchen
Автор

I like the idea of null object that do nothing, but im not too sure about making non-nullable types nullable

Roockert