Having full-blown interface support in Unity removes a huge source of constant friction, and opens up a new world of possibilities - I can't recommend this enough!
It's brilliant when you see how fast you explain really complex stuff in general. I really love your videos because I feel like I'm learning so much about various generic topics. Thanks a lot for your work, you'll have my support all the way long.
You inspired the usual 'wow' from me. And having spent the last four months or so writing several custom property drawers and attributes, i was happy to see i followed most of this. Cheers again for sharing your valuable expertise.
Getting a better understanding of why things like the Odin inspector/serializer does. The video is also a good reference to setting up property drawers.
The chad robot in the thumbnail is git-amend giving us the solution to the eternal pain the interface serialization is Thank you so much, I really didn't want to tie certain things to abstract classes just to have the convenience of drag-and-drop, and now I don't have to
If I'm that guy I'm not sure you'll see many more of those. Not a lot of stuff to add to the project anymore. One or two to revisit when I upgrade AI. I did get a really strong run of like 10-12 videos that I used something from... which was honestly game changing for me. Just wanted to make sure to engage, but I often don't have any improvment note ..so I'm just thanking him.
@myk3l9675 I was not offended. I set myself up for it to be honest. I'd have made fun of me for it long ago if i were you. More than once I was thought "well im committed to making a comment. the guy has helped me out loads...to bad i have literally nothing valuable to say". Edit: also for context git-amend did make some of the videos due to issues I was having in my project..or atleast they provided inspiration for videos. So I was infact the direct benefactor.
I remember commenting about this topic recently. This is a really helpful solution. I wish this functionality was built in to Unity. (I also wish that Odin came standard too)
As per usual : great tuto ! Bravo! I always find myself considering changes to my projects right after i see your videos. Especially : kudos on your design patterns implementations, they are great pratical examples! PS : i know it would be very time-consuming, but i feel you could make indepth version of your videos that last twice the time with examples, code snippets, because you talk fast and some subject are quite advanced imho ^^
Love your vídeos man, thank you for making them. You're seriously underrated. . . . But man do me a for and prepend your private member fields with an underscore!!!
"Wouldn't it be nice if you could assign objects by interface?" YES IT WOULD. If I had a nickel every time I thought this to myself I'd have like... fifty bucks.
May I ask you a minor question? I recently heard from OOP that they prefer composition to inheritance. Right now, it seems like you're using the interface in combination with the composition, but I'm going to ask you a question What are the benefits compared to DI injection? I'm sorry for the rudimentary question.
Here, the advantage is that we can drag and drop things that are in the scene or things that are Assets in the project like prefabs or scriptable objects. DI is more for things that do not derive from UnityEngine.Object, such as pure C# services or factory classes that can supply your dependencies at runtime. As far as composition vs inheritance, I think it depends on the situation. You can watch the video on the homepage of the channel if you haven't yet. Generally speaking, it is better to use composition than inheritance, but not always. You have to use your best judgement.
@@git-amend I watched the video and posted a comment. Teacher. Thank you for always answering the novice questions without getting annoyed. I'm asking you this question because the basis of my code is you and teacher Smack. That's why I'm trying to learn as much from you as possible, I prefer DI injection, but I asked you out of curiosity because your code prefers serialization. I really want it to be your Unity official tutorial. Thank you always.
How do you feel at this point about also doing the UI Toolkit version in the property drawer in these type of videos, or would it add too much time/complexity? Great stuff as always, thanks!
Thank you! Unfortunately, making something custom in UI Toolkit would essentially be a whole topic on it's own. And in this case it's not really necessary, we can piggyback on the existing GUI methods.
I believe there's a mistake in the video. At 11:45, line 19, you have `EditorGUI.ObjectField(position, label, underlyingProperty.objectReferenceValue, typeof(UnityEngine.Object), true)` meanwhile in the github the 4th parameter is different - it should be args.ObjectType I was trying to follow with you and actually type code you type in, in attempt to catch up with you and understand at least something.
Improvements and bugfixes happen sometimes after the video is released, so the video and the repository may not always match. You might find it more useful to reference the first commit, and then compare what has changed and why in subsequent commits.
A great video again 👍 What about for classes that are not Unity Object or Mono. Should we add SerializationCallbacks for each class and handle them ourselves?
I think that depends on what you are trying to do. In many cases, Unity has the [SerializeReference] attribute which was meant for anything that doesn't derive from UnityEngine.Object. However, it also lacks support for the inspector when it comes to interfaces. There are a few workarounds, such as making a base class that you can inherit from. Or build (or modify) a solution like the one in the video. I was thinking about making a serializable callbacks video too, maybe I'll do that one sooner than later.
You did a video on stats and modifiers a while back but I'm curios about how you would manage the full amount of player stats while keeping things like health, attack, defense, etc. Modular for use on other things like enemy agents. I'd consider something like a manager class and scriptable objects. maybe having a dedicate player manager and separate enemy/Npc manager? Is this in the right direction? also since its relevant, what interfaces would you implement in the process. Im still learning this stuff 🧐
These are complex questions that can't be answered in a YT comment. I recommend joining Discord and asking your question under the related video topic.
Unity does support serializing interfaces using [SerializeReference]. Since [SerializeField] serializes by values, and interfaces don't have a values. Unless I'm getting this wrong?
You will find that there is no support for this, and the field will not be visible in the inspector. [SerializeReference] public IDamageable item; Technically you could work around that with a custom inspector or drawer, or by using a base class that implements the interface. But there are other limitations as well. See: docs.unity3d.com/ScriptReference/SerializeReference.html
[SerializeReference] only supports serializing plain old class objects, not UnityEngine.Object references, and it also has no built-in Inspector support :(
@@git-amend what limitations tho? I always serialize interfaces as a base class (Like MonoBehaviour itself iirc) which then casted to an interface in the script. Only issue could arise is if I ignore OnValidate sanity check giving me an error if I placed wrong class there. I mean, this is not the proper clean solution, but it seems to work well. Yeah, basically I did 5:23 just what you started from.
Very useful tutorial as always, but then something bothering me, i see you are using unity 6 for this tutorial, yet still using the old imgui for editor stuff, is there any specific reason for that?, maybe it's easier or just your preferences.. Thank you in advance
I hope that doesn't bother you too much. I try to only introduce one complex topic per video. UI Toolkit is still new to most people, so that will have to be a separate video.
@git-amend thanks, indeed this topic already complex for most of us to handle, don't stop making it sir, anyway another thing about ui toolkit, if there any chance in future, can you cover about listview, multicolumn list view, tree view etc, with support for use editor binding via binding path... Currently it's just so weird for me, and also i see many question about that in unity discussion with no clear "true way"
The [SerializeReference] attribute is meant to work with regular class objects, meaning UnityEngine.Object types aren’t supported, and it lacks Inspector support by default.
I'm sorry, it's different from the video, but I'm asking because there's a problem. When moving on to the next scene in Unity, how do I call up and use cavas and player objects that contain various UI used in the previous scene in the next scene? And can you tell me how to maintain the reference values that I connected on the editor in unity?
Often people will use an extra scene to hold references that need to persist between scenes. You should watch a video like this one: ruclips.net/video/JFP-cCFID7o/видео.html
while using this i deskovered a problem you mite want to hear about. when you have multipal of the same script on diffrent components fx(enemy.Script with a attack.Interface). and you then select them all at the same time. the interface on the first component will override the one on the otheres. this isen,t the worst and you can work around this by only selecing one objeckt at a time. but i thote you mite want to know if you plan on updating the scripts
Une interface est un contrat que passe une classe, qui garanti l'implémentation d'un (ou plusieurs) membre (dans l'exemple : la méthode Damage(int amount)). Cela permet que plusieurs objets différents (une classe "héro",une classe "ennemi" ou une classe "porte" par exemple, toutes les classes auxquelles tu veut pouvoir infliger des dégâts dans ton projet) qui implémentent cette interface auront forcément une méthode publique Damage(int amount). Une interface étant un type cela permet aussi de traiter 'hero' et 'ennemi' comme étant des IDamageable (et ainsi mettre des objets de nature différente dans une même liste par exemple). C'est très simplifié, mais j'espère que cela clarifie la question ;) PS : les interface sont des outils C#, ne limite pas tes recherches a Unity ^^ PPS : vu que tu a l'air de t'appeler pierre, je me suis permis de répondre en français ;) (google trad corrigera mon erreur au cas ou, j'espère)
😉Hi G Can you make an video for me i have struggled in the middle path of unity concept. I know loops , conditions, Interface, abstract, but not like you serialise and making😵 anything custom please make an video for a guid what topic🤗 are here in unity programmer. I dont know what are the concpets are here i am learning like an islands 🏝 in ocen pleace givr an clarify the conpets or need to learn in unity programing like you. I need to become an coder like you please guidence. Iam making an smoke fire to any one see my and give your hands to clarify me.😅not able to buy an courses
If you have no labels!! Make sure you put InterfaceReferenceUtil.OnGUI(position, underlyingProperty, label, args); after EditorGUI.EndProperty(); in your InterfaceReferenceDrawer(.cs) script.
This setup is just meant for things that inherit from UnityEngine.Object. For other objects (System.Object) technically that is what [SerializeReference] is meant to be used for... though it lacks support for the Inspector as well for interfaces. But you could create a Base class that implements an interface and then inherit from that. Some examples here: docs.unity3d.com/ScriptReference/SerializeReference.html
@@git-amend The base class seems promising, but after giving it a try, only its label appears while the drag-and-drop field is missing, which is odd. [SerializeReference] public Base Test;
Happy Sunday, code warriors! 🎉 Drop a comment and smash that 👍💥
[X] Extremely useful tool
[X] Great tutorial for custom editors
[X] Bafflement that this feature isn't built into Unity
Thank you, I agree 💯 this should already be a feature of the engine!
Having full-blown interface support in Unity removes a huge source of constant friction, and opens up a new world of possibilities - I can't recommend this enough!
Couldn't agree more 💯
These advanced C# techniques are simply awesome! Great video as usual from you. Thanks for your work.
My pleasure!
One of the best pieces of Unity content I've seen in a long time. Amazing stuff!
Wow, thanks! Glad to hear that!
It's brilliant when you see how fast you explain really complex stuff in general. I really love your videos because I feel like I'm learning so much about various generic topics.
Thanks a lot for your work, you'll have my support all the way long.
Great to hear! Thank you!
You inspired the usual 'wow' from me. And having spent the last four months or so writing several custom property drawers and attributes, i was happy to see i followed most of this.
Cheers again for sharing your valuable expertise.
That is awesome to hear! Thanks for the comment!
Your channel was much needed to me as a beginner game dev. I used to watch tarodev but he stopped uploading. You are godsend 😊
Happy to hear that!
I love these advanced takes ! Such talent and awesome presentation for years now! :) Thank you Sir!
My pleasure!
Getting a better understanding of why things like the Odin inspector/serializer does. The video is also a good reference to setting up property drawers.
Good, glad to hear that! I made a few refinements to the drawer code in the repo if you want to review that too.
this is sick! We thought about dragging interfaces in on Friday, but we couldn't find a way, so thank you very much!
You're welcome!
It's amazing how you explain, you're the beast, I love your code
I appreciate that!
The chad robot in the thumbnail is git-amend giving us the solution to the eternal pain the interface serialization is
Thank you so much, I really didn't want to tie certain things to abstract classes just to have the convenience of drag-and-drop, and now I don't have to
Nice :)
I'm earlier than the guy who's going to say that you always post a video on exactly what problem he was having!
Hahah, very nice... and FIRST!
If I'm that guy I'm not sure you'll see many more of those. Not a lot of stuff to add to the project anymore. One or two to revisit when I upgrade AI.
I did get a really strong run of like 10-12 videos that I used something from... which was honestly game changing for me. Just wanted to make sure to engage, but I often don't have any improvment note ..so I'm just thanking him.
@@Fitz0fury oh. I was just teasing, not hating!
@myk3l9675 I was not offended. I set myself up for it to be honest. I'd have made fun of me for it long ago if i were you. More than once I was thought "well im committed to making a comment. the guy has helped me out loads...to bad i have literally nothing valuable to say".
Edit: also for context git-amend did make some of the videos due to issues I was having in my project..or atleast they provided inspiration for videos. So I was infact the direct benefactor.
I remember commenting about this topic recently. This is a really helpful solution. I wish this functionality was built in to Unity. (I also wish that Odin came standard too)
I couldn't agree more!
As per usual : great tuto ! Bravo!
I always find myself considering changes to my projects right after i see your videos.
Especially : kudos on your design patterns implementations, they are great pratical examples!
PS : i know it would be very time-consuming, but i feel you could make indepth version of your videos that last twice the time with examples, code snippets, because you talk fast and some subject are quite advanced imho ^^
Thanks for the comment. I'll keep your feedback in mind, though time is always limited.
Love your vídeos man, thank you for making them. You're seriously underrated.
.
.
.
But man do me a for and prepend your private member fields with an underscore!!!
Thanks for the comment, but I will not be using underscores as prefixes.
@@git-amendBoooooo! Whose naming convention do you follow if not Microsoft's?
"Wouldn't it be nice if you could assign objects by interface?" YES IT WOULD. If I had a nickel every time I thought this to myself I'd have like... fifty bucks.
Hahah 💯
20 min and you solved the biggest pain in Unity? I am amazed! and a bit scared :D
Haha well it took most of Friday night to be honest... condensed down into 20 mins!
RequireableInterface That's a really good keyword! always Thanks!
May I ask you a minor question? I recently heard from OOP that they prefer composition to inheritance.
Right now, it seems like you're using the interface in combination with the composition, but I'm going to ask you a question
What are the benefits compared to DI injection?
I'm sorry for the rudimentary question.
Here, the advantage is that we can drag and drop things that are in the scene or things that are Assets in the project like prefabs or scriptable objects. DI is more for things that do not derive from UnityEngine.Object, such as pure C# services or factory classes that can supply your dependencies at runtime.
As far as composition vs inheritance, I think it depends on the situation. You can watch the video on the homepage of the channel if you haven't yet. Generally speaking, it is better to use composition than inheritance, but not always. You have to use your best judgement.
@@git-amend I watched the video and posted a comment. Teacher.
Thank you for always answering the novice questions without getting annoyed.
I'm asking you this question because the basis of my code is you and teacher Smack.
That's why I'm trying to learn as much from you as possible, I prefer DI injection, but I asked you out of curiosity because your code prefers serialization.
I really want it to be your Unity official tutorial.
Thank you always.
Thank you so much for this! So useful...
You're so welcome!
Two days ago, I was searching for that - it's as if you can read minds!
Nice, glad to hear that!
How do you feel at this point about also doing the UI Toolkit version in the property drawer in these type of videos, or would it add too much time/complexity? Great stuff as always, thanks!
Thank you! Unfortunately, making something custom in UI Toolkit would essentially be a whole topic on it's own. And in this case it's not really necessary, we can piggyback on the existing GUI methods.
This is a gamechanger, waaaaaaaaaaaaaaaaaaaaaauw!
Glad to hear that! Hope it helps you out!
Solid as always and invaluable information.
Much appreciated!
Happy Sunday!
Same to you!
I believe there's a mistake in the video.
At 11:45, line 19, you have `EditorGUI.ObjectField(position, label, underlyingProperty.objectReferenceValue, typeof(UnityEngine.Object), true)`
meanwhile in the github the 4th parameter is different - it should be args.ObjectType
I was trying to follow with you and actually type code you type in, in attempt to catch up with you and understand at least something.
Improvements and bugfixes happen sometimes after the video is released, so the video and the repository may not always match. You might find it more useful to reference the first commit, and then compare what has changed and why in subsequent commits.
A great video again 👍
What about for classes that are not Unity Object or Mono.
Should we add SerializationCallbacks for each class and handle them ourselves?
I think that depends on what you are trying to do. In many cases, Unity has the [SerializeReference] attribute which was meant for anything that doesn't derive from UnityEngine.Object. However, it also lacks support for the inspector when it comes to interfaces. There are a few workarounds, such as making a base class that you can inherit from. Or build (or modify) a solution like the one in the video. I was thinking about making a serializable callbacks video too, maybe I'll do that one sooner than later.
You did a video on stats and modifiers a while back but I'm curios about how you would manage the full amount of player stats while keeping things like health, attack, defense, etc. Modular for use on other things like enemy agents. I'd consider something like a manager class and scriptable objects.
maybe having a dedicate player manager and separate enemy/Npc manager? Is this in the right direction?
also since its relevant, what interfaces would you implement in the process. Im still learning this stuff 🧐
These are complex questions that can't be answered in a YT comment. I recommend joining Discord and asking your question under the related video topic.
Another great video, How is this not supported as a built in feature in unity ? Amazing ! Thanks !
Yes, I wish it were native, it would be so useful!
Seriously, everyone should just buy Odin. It's amazing.
Yes, I agree... black friday coming soon, so no excuses!
Unity does support serializing interfaces using [SerializeReference]. Since [SerializeField] serializes by values, and interfaces don't have a values.
Unless I'm getting this wrong?
You will find that there is no support for this, and the field will not be visible in the inspector.
[SerializeReference] public IDamageable item;
Technically you could work around that with a custom inspector or drawer, or by using a base class that implements the interface. But there are other limitations as well. See: docs.unity3d.com/ScriptReference/SerializeReference.html
[SerializeReference] only supports serializing plain old class objects, not UnityEngine.Object references, and it also has no built-in Inspector support :(
@@git-amend what limitations tho? I always serialize interfaces as a base class (Like MonoBehaviour itself iirc) which then casted to an interface in the script. Only issue could arise is if I ignore OnValidate sanity check giving me an error if I placed wrong class there. I mean, this is not the proper clean solution, but it seems to work well. Yeah, basically I did 5:23 just what you started from.
Thank you!
You're welcome!
Very useful tutorial as always, but then something bothering me, i see you are using unity 6 for this tutorial, yet still using the old imgui for editor stuff, is there any specific reason for that?, maybe it's easier or just your preferences..
Thank you in advance
I hope that doesn't bother you too much. I try to only introduce one complex topic per video. UI Toolkit is still new to most people, so that will have to be a separate video.
@git-amend thanks, indeed this topic already complex for most of us to handle, don't stop making it sir, anyway another thing about ui toolkit, if there any chance in future, can you cover about listview, multicolumn list view, tree view etc, with support for use editor binding via binding path... Currently it's just so weird for me, and also i see many question about that in unity discussion with no clear "true way"
Do you use Midjourney for your thumbnails?
Sometimes, and yes today this is from Midjourney with a heavy dose of Photoshop.
No idea why this is not built-in...tysm
You're welcome, maybe Unity 7 will support this...
I've heard Unity 6 now has its own serializer
isnt unity already supported this by [SerializeReference] ?
The [SerializeReference] attribute is meant to work with regular class objects, meaning UnityEngine.Object types aren’t supported, and it lacks Inspector support by default.
I'm sorry, it's different from the video, but I'm asking because there's a problem. When moving on to the next scene in Unity, how do I call up and use cavas and player objects that contain various UI used in the previous scene in the next scene? And can you tell me how to maintain the reference values that I connected on the editor in unity?
Often people will use an extra scene to hold references that need to persist between scenes. You should watch a video like this one: ruclips.net/video/JFP-cCFID7o/видео.html
Whats your system specs you are using?
Nice
Should i scrap this for property drawer Extensions?
Thanks
Omg ty bro
Very welcome!
while using this i deskovered a problem you mite want to hear about.
when you have multipal of the same script on diffrent components fx(enemy.Script with a attack.Interface).
and you then select them all at the same time. the interface on the first component will override the one on the otheres. this isen,t the worst and you can work around this by only selecing one objeckt at a time. but i thote you mite want to know if you plan on updating the scripts
interesting but I don't understand much, not even what it's basically used for...😭 thanks anyway 😂
Maybe we'll have a video on using interfaces soon, I feel like you are not alone.
@@git-amend yes i'm just looking at what is an interface on unity website :)
Une interface est un contrat que passe une classe, qui garanti l'implémentation d'un (ou plusieurs) membre (dans l'exemple : la méthode Damage(int amount)).
Cela permet que plusieurs objets différents (une classe "héro",une classe "ennemi" ou une classe "porte" par exemple, toutes les classes auxquelles tu veut pouvoir infliger des dégâts dans ton projet) qui implémentent cette interface auront forcément une méthode publique Damage(int amount).
Une interface étant un type cela permet aussi de traiter 'hero' et 'ennemi' comme étant des IDamageable (et ainsi mettre des objets de nature différente dans une même liste par exemple).
C'est très simplifié, mais j'espère que cela clarifie la question ;)
PS : les interface sont des outils C#, ne limite pas tes recherches a Unity ^^
PPS : vu que tu a l'air de t'appeler pierre, je me suis permis de répondre en français ;) (google trad corrigera mon erreur au cas ou, j'espère)
@@suntonio7187 oui , merci, mes recherches m'ont amené à comprendre exactement ce que tu as expliqué 😉
😉Hi G Can you make an video for me i have struggled in the middle path of unity concept. I know loops , conditions, Interface, abstract, but not like you serialise and making😵 anything custom please make an video for a guid what topic🤗 are here in unity programmer. I dont know what are the concpets are here i am learning like an islands 🏝 in ocen pleace givr an clarify the conpets or need to learn in unity programing like you. I need to become an coder like you please guidence. Iam making an smoke fire to any one see my and give your hands to clarify me.😅not able to buy an courses
If you have no labels!! Make sure you put InterfaceReferenceUtil.OnGUI(position, underlyingProperty, label, args); after EditorGUI.EndProperty(); in your InterfaceReferenceDrawer(.cs) script.
I'm wondering if we can assign a class that has an interface but doesn't inherit from MonoBehaviour or ScriptableObject.
This setup is just meant for things that inherit from UnityEngine.Object. For other objects (System.Object) technically that is what [SerializeReference] is meant to be used for... though it lacks support for the Inspector as well for interfaces. But you could create a Base class that implements an interface and then inherit from that. Some examples here: docs.unity3d.com/ScriptReference/SerializeReference.html
@@git-amend The base class seems promising, but after giving it a try, only its label appears while the drag-and-drop field is missing, which is odd.
[SerializeReference] public Base Test;