Easy Editor Windows in Unity with Serialized Properties

Sdílet
Vložit
  • čas přidán 17. 07. 2024
  • In this video we take a look at how to dynamically draw Editor Windows in Unity by harnessing the power of the SerializedObject and SerializedProperty classes.
    We create a tool that will automatically draw an inspector-like editor window, for any object we pass into it.
    Be sure to LIKE and SUBSCRIBE if you enjoyed this guide! Share the video for extra love!
    - - - - - - - - - - - - -
    I've set up a Discord so viewers can hangout, chat and share their own game dev tips and tricks. It's also a perfect place to hear about what videos I'm working on, or discussing episodes in more detail with other members of the Game Dev Guide community.
    You're invited to join the Discord at / discord
    - - - - - - - - - - - - -
    Socials:
    Twitter - / gamedevguideyt
    Facebook - / gamedevguideyt

Komentáře • 124

  • @BenjaminK123
    @BenjaminK123 Před 3 lety +2

    i love your videos, you pack so much into 10 minutes but at the end of it you know the process and personally i do revisit your videos allot and slowly work my way through them but that first time watch is like a strong hit of coffee and taste so dam good.

  • @jack4law
    @jack4law Před 5 lety +4

    Awesome video as ever! I love the explanation before the main tutorial started... Improved my understanding of what I was going to learn. Good job!

  • @marche4ever
    @marche4ever Před rokem

    i like how you show the problem you encounter first, then present a solution, very well-made video!

  • @BeeGameDev
    @BeeGameDev Před 4 lety

    This is excellent and just what I needed. Also, I feel like you managed to condense some of the 40+min impenetrable tutorials down into just 10 minutes. Time saver! Cheers!

  • @MichaelFurmedge
    @MichaelFurmedge Před 4 lety +1

    High quality video dude, I really appreciate the time you're taking to make these.

  • @gonzaloescamilla8488
    @gonzaloescamilla8488 Před 4 lety +135

    Please, it would be awesome if you could create more detailed videos on how to create custom editor in Unity.

    • @vincentp9673
      @vincentp9673 Před 4 lety +7

      i would really like a tutorial playlist on a more or less "full" game of GameDevGuide

    • @TiimedArts
      @TiimedArts Před 4 lety +3

      The information from the video is enough to program your own custom editor. You just need your own ideas lmao

    • @dragonboyx123
      @dragonboyx123 Před 4 lety +16

      @@TiimedArts To be honest, I found this a bit confusing. Some of the things I wanted to learn from the video, he skipped them. I have ideas, but I need someone to teach me about how to operate the Editor.

    • @shadmansudipto7287
      @shadmansudipto7287 Před 3 lety +5

      @@dragonboyx123 that's how this channel is man, he's got even worse videos where he doesn't show the code at all for shaders and doesn't share the project files either.

    • @kaleb_t4818
      @kaleb_t4818 Před 3 lety

      @@dragonboyx123 did you find any thing useful ?

  • @geoffreyhendrikx
    @geoffreyhendrikx Před 4 lety +27

    I just found this channel and i love it already.
    You explaining everything very well.

  • @322ss
    @322ss Před 4 lety

    Thank you! Probably couldn't have been able to come up with such a neat solution without this video... insightful stuff. I've only managed to find few articles about using SerializedObjects...

  • @Dizastrophe
    @Dizastrophe Před 4 lety +33

    Would love a more in depth video showing all the different kinds of things you can do!

  • @euriherasme
    @euriherasme Před 3 lety

    Thank you so so so so much, this and every single one of your tutorials are really awesome, I cannot thank you enough!

  • @raycodes7393
    @raycodes7393 Před 2 lety

    I've been looking for this for a week now ARRRGH
    Thank you!

  • @meteturkay
    @meteturkay Před rokem

    I always find you when i most needed, you're best

  • @paulthompson52
    @paulthompson52 Před 3 lety

    Would like to see more videos from you on this subject...really awesome work!!

  • @HadiLePanda
    @HadiLePanda Před 4 lety +1

    Really useful for organizing, thanks for the tutorial!

  • @ryancassidy3033
    @ryancassidy3033 Před 5 lety

    Great stuff, man. Definitely going to try to utilise this!

  • @anaibrahim4361
    @anaibrahim4361 Před 4 lety

    Didn't find what to see
    Exactely what i was looking for thanks soo much
    You gave it in fantastic presentation

  • @limitless6572
    @limitless6572 Před 2 lety +1

    I just found you, amazing tutorials. Subscribed!

  • @jean-michel.houbre
    @jean-michel.houbre Před 3 lety

    Thank you for this very interesting video. I took a big step in my discovery of editor scripts, but I think I'll have to review it again ^^

  • @ChristianRoyUtah
    @ChristianRoyUtah Před 5 lety +1

    Wow! I love this! Thank you!

  • @rofosaurus3758
    @rofosaurus3758 Před 3 lety +1

    You just blew my mind mate.

  • @wasteurtime5677
    @wasteurtime5677 Před rokem

    watched this video 3 years ago. Had no idea how to do any of this. Now i'm making my own tools. Thank you for inspiring me 😭😭

  • @eneziofilho5312
    @eneziofilho5312 Před 2 lety

    You just destroyed all my doubts, thanks 🤘

  • @ramonmelo2799
    @ramonmelo2799 Před 4 lety

    Super nice! Thanks for the tutorial ! :)

  • @RobinPortnoff
    @RobinPortnoff Před 4 lety

    Thanks, Matt for all the great tutorials. I saw your event sequencing tool whizzing by at the start of the video. Any plan for a tutorial on node-based tools? I would greatly appreciate it!

  • @nafurachan9061
    @nafurachan9061 Před 4 lety +2

    would you cover how to build those node editors? That looks that it'd be immensely useful!
    Thanks for the videos!

  • @Sean-hd1bp
    @Sean-hd1bp Před 4 lety

    Wow! This is so useful!

  • @arthur-monteath
    @arthur-monteath Před 6 měsíci

    I love your channel!

  • @DonDisainer
    @DonDisainer Před 2 lety

    great info!!! tnx a lot!!!

  • @iamjohnhult
    @iamjohnhult Před 3 lety +2

    Did no one else see that comment at 1:24? "Change these fuckers". A game dev in my liking.

  • @blincey
    @blincey Před 4 lety

    This video was exactly what I was looking for! I would really love it if you went into more detail about the individual features of the Unity Window editing; or other such features :)

  • @gonzaloescamilla8488
    @gonzaloescamilla8488 Před 4 lety +4

    I just fouund this channel. Its Amazing!"!!

  • @RickMcMichael
    @RickMcMichael Před 3 lety +2

    Any chance that you could release the source code so I can check my files? The use case isn't related to mine
    Specifically trying to use this type of window to open from a "Menu" item and grab all of its value so I can further sort groups separated by headers and change them more easily.

  • @Andrew90046zero
    @Andrew90046zero Před 4 lety +1

    I would like to see how you made some of those node graphs in the intro. If you did actually make those. or other magical looking editors that you've made.

  • @TheWalruzz
    @TheWalruzz Před 4 lety +1

    While I usually hate video tutorials (I prefer to visually scan text tutorials to save me time) your videos are truly amazing and straight to the point. And even though I rolled out my own solutions to some of the problems you give tips for, I always find something new to learn and improve upon in my project after watching your guides. 10/10 would recomend to anyone making their indie games

  • @DamienPup
    @DamienPup Před 4 lety +1

    how do you make it so you can chage the amount of elements in a array?

  • @potatoking5602
    @potatoking5602 Před 3 lety

    This whole video is very meta, very useful too tho

  • @elektra81516
    @elektra81516 Před 4 lety +1

    This is why I use Unity over anything else, love custom editors!

    • @teemuleppa3347
      @teemuleppa3347 Před 2 lety

      Unity is not the only engine that allows this

  • @Rajivrocks-Ltd.
    @Rajivrocks-Ltd. Před 4 lety

    Very insightful video!

  • @logan4179
    @logan4179 Před 3 lety

    Nice tutorial, but I felt a bit lost. I can't find any good, authoritative videos/courses on Unity editor scripting that go from the ground up. Were there any that you learned and would recommend, or did you just have to piece together info from what you could find?

  • @riekumar6999
    @riekumar6999 Před 2 lety

    Is there a video on how to manipulate scene objects in an editor window? I would love to create an event sequencer.

  • @minecraftermad
    @minecraftermad Před 4 lety

    how would i go about setting the names for the buttons that are drawn? currently i'm trying to just find a property with the name "name" and set it's value as the name if it's a string... but it seems kind of jank

  • @pokebytes
    @pokebytes Před 2 lety

    Such a helpful tutorial thank you! Question tho, I got everything working and I have a list of "SkinComplexes" and each of them contain scriptable object class "Skin". When I click on the button then all the Skin values are shown and I can put Skin scriptable object in it. Now I want similary to get "Skin" properties displayed if I have assigned it but I have tried so many things and still can't access those properties. Do you have any ideas how I could access them and display them?

  • @realog7692
    @realog7692 Před 2 lety

    I want to edit inspector things in in-game setting like
    Controlling poset possessing with toggle or camera view distance

  • @akilaakila7312
    @akilaakila7312 Před 2 lety

    I find the legendary developer teacher

  • @simoncodrington
    @simoncodrington Před 4 lety

    Awesome video mate. Haven't seen many editor / gui unity videos. Keen on seeing what you come up with next.

  • @victorgonzalezrivera6806
    @victorgonzalezrivera6806 Před 4 lety +1

    I have a problem in 6:17 where you put the string parameter "gameData" in findProperty, I dont understand what are you referring with that. Hope you can answer me. Thank you so much for the vid!

    • @TheRandomCS
      @TheRandomCS Před 4 lety +1

      Its the name of the list in his game data class, you can see the inspector for it at 2:32. The signature being something like 'List gameData'. You want the lower case version since that's the variable name.

  • @kyanrowse4150
    @kyanrowse4150 Před 3 lety

    Is it possible to use this to change the element name. So if i have an array floats in the inspector i don't have element 0, element 1 etc I can put a name so if someone who doesn't know about the scripts contents can just take one look and be like hey that's what that array index is for.

  • @mg6554
    @mg6554 Před rokem

    please can you explain to me what is the gameData on line 17 GameDataEditorWindow

  • @hemanthadapala6910
    @hemanthadapala6910 Před rokem

    how did you created those buttons "Play&Simulate", "Mission Control" and "Scene Collections" if anyone knows how to do that ?

  • @dominiauk
    @dominiauk Před 5 lety

    Brilliant stuff.

  • @silverfoxstudio4452
    @silverfoxstudio4452 Před 3 lety

    So this is the video that every AssetStore publisher watch for make a editor window

  • @awesomedata8973
    @awesomedata8973 Před 5 lety +2

    This is great, but it should really show how to make the ScriptableObject list of classes. Maybe provide some details?

    • @GameDevGuide
      @GameDevGuide  Před 5 lety

      Hey, so there's a Discord server for the community linked in the description which was set up for follow ups on videos such as this, and to discuss video topics in more detail.
      We're also actually discussing this over there too, so you might find it useful. Feel free to join if you wish to get involved. 😊

  • @LuizMoratelli
    @LuizMoratelli Před 4 lety

    Please, do more videos about of it.

  • @MDSky
    @MDSky Před 3 lety

    8:20 that looks good, but if you could be so kind as to exsplain how to change the boxes background colours that would help alot.

  • @owendugmore1057
    @owendugmore1057 Před 4 lety +1

    Great video. Is it just me, or is custom editor scripting not very well documented in the official Unity docs?

  • @nove1398
    @nove1398 Před 3 lety +1

    How Do I populate the the list though?

  • @feliscape
    @feliscape Před rokem

    When I add a new object to the list via a gui button it doesn't update the sidebar. How can I fix this? The button operates on a reference to the scriptable object assigned when opening the window.

  • @benayamanuel
    @benayamanuel Před 3 lety

    Hey man, just got frustated because all my editor scripts (basically all scripts in Assembly-C#-Editor.dll) couldn't find other classes that sit on Assembly-C#.dll. (missing a directive or assembly reference) My editor scripts created just few weeks ago and they did just fine. But this morning this bug showed up and all my editor code is dead. Bcs they couldn't find the base class. Any idea on this ? Thanks

  • @Gers217
    @Gers217 Před 5 lety +2

    How do I change the number of elements of my ScriptableObject?

    • @AmanKumar-tu2og
      @AmanKumar-tu2og Před 4 lety +1

      Add this to the end of DrawProperties Method
      if (GUILayout.Button("Add Item"))
      {
      prop.InsertArrayElementAtIndex(prop.arraySize);
      }
      if (GUILayout.Button("Remove Item") && prop.arraySize > 0)
      {
      prop.DeleteArrayElementAtIndex(prop.arraySize - 1);
      }
      EditorGUILayout.EndHorizontal();
      And, Add these to the start and end of OnGUI method in the customeditorwindow :
      > serializedObject.Update();
      currentProperty = serializedObject.FindProperty("propertyname");
      DrawProperties(currentProperty, true);
      > serializedObject.ApplyModifiedProperties();

  • @GreenClover0
    @GreenClover0 Před 3 lety +1

    I have the impression that we are quite similar. I like to create systems that I can improve later on. I think I like it even more than the game development itself. So I'm glad I found this channel by accident while working on my first custom editor. Keep up the good work

  • @TESkyrimizer
    @TESkyrimizer Před 4 lety +1

    That was the greatest thing I have ever seen. Holy crap.

  • @dahiyabunty1
    @dahiyabunty1 Před 4 lety +1

    sir..
    do you have project on github???

  • @mdistudio7875
    @mdistudio7875 Před 4 lety

    Hi bro thanks so much for this tutorial,
    But how can i make array of inheritance classes
    Ex.
    Public class base :MonoBehaviour
    {
    //some data
    Public child[] _child
    [system. Serializeble]
    Public class child : base
    {
    //some data
    Public subChild _subChild
    [system. Serializeble]
    Public subChild : child
    {
    //some data
    }
    }
    }
    And to access them?

  • @ecthoart3815
    @ecthoart3815 Před 3 lety +2

    How would I get this to work with a ScriptableObject that is not set up as an array?

    • @LuisVasquezVega
      @LuisVasquezVega Před 2 lety +1

      Did you find a solution? I make it work but serialized values inside nested groups are getting draw in the sidebar.

  • @tayyabmujeeb7621
    @tayyabmujeeb7621 Před 3 lety

    can we convert editor window into canvas?

  • @thedazzledazz4719
    @thedazzledazz4719 Před 3 lety

    I know this is years old so I probably wont get a reply, but how come when other people do this the non editor classes (in this instance "GameDataObject") come up in the autocomplete for others but for me it always comes up with a red line (even though it still works like that, it's annoying to have to repeatedly check the spelling and to manually type out all the functions)...
    Is there a setting I'm missing somewhere?

  • @minecraftermad
    @minecraftermad Před 4 lety +1

    for me the edited values revert the changes made to the object when switching between editor and playmode
    i've tried:
    Undo.RegisterCompleteObjectUndo(ObjectThatWasModified, "update Paths");
    and in a custom editor gui i've tried to do:
    serializedObject.ApplyModifiedProperties();
    i've also tried calling the custom editor from the editor window with a handle with both of those on.

    • @JacobSmith-ts2gq
      @JacobSmith-ts2gq Před 4 lety

      try calling setdirty when you change the values it should refresh the info

    • @minecraftermad
      @minecraftermad Před 4 lety

      @@JacobSmith-ts2gq isnt set dirty deprecated?

    • @JacobSmith-ts2gq
      @JacobSmith-ts2gq Před 4 lety

      @@minecraftermad dont know, but it i had the same problem in one of my projects and it worked

    • @JacobSmith-ts2gq
      @JacobSmith-ts2gq Před 4 lety

      also if you are referencing custom classes they should have a [System.Serializable] ubove it

  • @badrballish9328
    @badrballish9328 Před 3 lety

    Thank you very much.

  • @lesthodson2802
    @lesthodson2802 Před 2 lety +2

    1:23 "CHANGE THESE FUCKERS"
    I see what you did there. :D

  • @TheMadMuffin
    @TheMadMuffin Před 2 lety +2

    I tried to follow this tutorial but my data isnt a list called gameData, I have no idea how to translate any of this to fit the shape of MY data. Can someone explain how to make this work for any other content that isnt a list called gameData?

    • @jonahmcconnell4818
      @jonahmcconnell4818 Před 2 lety

      I just worked through the tutorial and from what I can tell it requires a bit of modification either way working in versions after the one the video was recorded in (though I'm not sure). This Discord in the description does have channels specifically for this sort of help if you need it.

  • @silverfoxstudio4452
    @silverfoxstudio4452 Před 3 lety

    Why you don't zoom the ide ?

  • @__dane__
    @__dane__ Před 2 lety

    I wish there were more videos about property drawers instead of editor windows. Way more often than not I want to display properties in within existing editor windows

  • @dirt410
    @dirt410 Před rokem

    how should i structure my data so that this works? no matter how many times i've tried to implement this it never works for me. something is always broken. Either arrays and lists duplicate themselves or they don't show up at all. and if i try to add the sidebar, none of the fields show up. i'm completely lost.

    • @feliscape
      @feliscape Před rokem

      I had a similar issue, and it seems to be because I was using nested scriptable objects. You need to use a serialized class for it to work. This is how my class looks:
      [System.Serializable]
      public abstract class CutsceneAction
      {
      public string name;
      public float duration;
      public abstract IEnumerator Play();
      }
      This shows up properly

  • @asrielmandrak7220
    @asrielmandrak7220 Před 4 lety +2

    The editor is blank. It does not draw anything. In fact, even the button does not appear in inspector.

  • @francyleomatos7104
    @francyleomatos7104 Před 4 lety +1

    Please create more videos related to EditorWindown,
    how to put timeline and components please, please, please, please!

  • @lewaplay
    @lewaplay Před 3 lety

    I'm trying to do this for 5 days and it still doesn't work

  • @sandwich9560
    @sandwich9560 Před 4 lety

    For those wondering how to refresh the Editor Window(the field being edited will not change it values) when you clicked on the sidebar button,
    protected void DrawSideBar(SerializedProperty prop)
    {
    foreach (SerializedProperty p in prop)
    {
    if (GUILayout.Button(p.displayName))
    {
    _selectedPropertyPath = p.propertyPath;
    //Add this
    EditorGUIUtility.editingTextField = false;
    }
    }
    if (!string.IsNullOrEmpty(_selectedPropertyPath))
    {
    SelectedProperty = SerializedObject.FindProperty(_selectedPropertyPath);
    }
    }

  • @nove1398
    @nove1398 Před 3 lety

    [selectedProperty.FindPropertyRelative] this method is not finding the property name that I passed in.

  • @tae6175
    @tae6175 Před 3 lety +8

    Me just learning Unity and have basic C# knowledge watching this video: yeah.. I have no idea what's he talking about.

    • @Senayoshy
      @Senayoshy Před rokem +1

      this is me right now so im just copying his script and seeing if it works.
      spoilers: it doesn't

    • @tae6175
      @tae6175 Před rokem

      @@Senayoshy 😂relatable

  • @vladisslavss
    @vladisslavss Před 4 lety

    Great!

  • @tayyabmujeeb7621
    @tayyabmujeeb7621 Před 3 lety +1

    Any one who can help regarding this?

  • @davidkokoski4392
    @davidkokoski4392 Před 2 lety

    Also, in case I wasn't the only one confused about the lastPropertyPath check thing (the "stop child properties from being drawn over iteration") and ALSO ran into the exact problem I did with the array/collection elements within the list we are currently trying to slap into our editor window repeating itself just like he said we were trying to avoid (I have a list within the list I'm trying to draw here), here is was I found out:
    TLDR: Add
    lastPropertyPath = p.propertyPath;
    inside
    foreach (SerializedProperty p in prop)
    {
    if (p.isArray == true && p.propertyType == SerializedPropertyType.Generic)
    {
    ...
    My poor explanation of why:
    (1) The idea behind the lastPropertyPath check in the else statement of DrawProperties is that it a) checks that the lastPropertyPath has been set somewhere (by checking that it isn't empty like we initialized it to be) and b) checks that the latest property path we looked at in the last loop (hence the name lastPropertyPath) we were working with is actually contained in the property path we are looking at right now.
    The idea behind b) is we are trying to see if the current property's path (the p.propertyPath) shows that it is a "child" of the lastProperty path we drew. If it is, that means it must be a child of an array/collection. NOTE: This assumes that lastPropertyPath ALWAYS contains the path of the last property we were looking at in the loop, so we can always compare the current property path (p.propertyPath) to the previous property path (lastPropertyPath). So, if the lastPropertyPath happened to be that of an array/collection, and the current property path CONTAINS that exact path within it, that means the current property path MUST be a child of a collection! If that is the case, it should have already been drawn in the previous if statement (we are in the else statement now), so we want to avoid redrawing it as if its a singular property (which is exactly what the code AFTER this check does for you if your property isn't a child of anything and is just a good old fashioned non-collection-related SerializedProperty). Boom! That explains how that whole "stop child properties from being drawn over iteration" is supposed to work.
    HERE IS WHY I found out the code didn't do that very thing I explained it was going to do...
    The Problem:
    We only assigned lastPropertyPath in two places: (1) when we initialized it to be empty before entering the foreach loop and (2) when we were in the case that the current property wasn't related to a a collection at all (that whole lastPropertyPath = p.propertyPath after the check we described with the "continue"). We never assigned lastPropertyPath when we were dealing with an array/collection! That means lastPropertyPath will never ever correspond to a collection, which means the check that is meant to see if the current property path contains an array's property path will never work. Your lastPropertyPath will never be that of a collection.
    Because of that, we will never be able to check b) properly. It's whole point is to see if the current property's path shows its a child of a collection, which is found out by seeing if the property's path contains the last collection's path.
    The simple fact is, lastPropertyPath needs to hold up to its name of always containing the propertyPath of the last property we were looking at, whether it satisfies p.isArray or not.
    So... TLDR... just make sure lastPropertyPath is being assigned inside the if(p.isArray == true ...) part of the foreach loop, as well as every other possible part.
    Phew, that was a lot of words. Like I said, "poor explanation" XD

  • @hojaverde5265
    @hojaverde5265 Před 5 lety

    Are you using Odin serializer? I want to get it but I'm not totally sure

    • @GameDevGuide
      @GameDevGuide  Před 5 lety

      Nope this is just default unity!

    • @joaniepepin4968
      @joaniepepin4968 Před 4 lety

      Probably late, but I got it at the latest sale and I must say, I am getting way more use out of it than I ever thought I would! Adding a button in the editor with one line of code allows to do so many things that I never would have thought possible and it saves a lot of time in the long run!

  • @invntiv
    @invntiv Před 4 lety

    How is this channel not massive

  • @AllDayBikes
    @AllDayBikes Před 3 lety

    "Change these fuck**s" nice haha

  • @shannonblack1394
    @shannonblack1394 Před rokem

    nice easter egg at 1:24😅

  • @Inf4mousKidGames
    @Inf4mousKidGames Před 4 lety

    Umm where the heck does currentProperty come from???
    it wasnt even defined

    • @Lelefant_
      @Lelefant_ Před 4 lety +1

      It is defined in ExtendedEditorWindow as protected variable, so it can be used in the deriving EditorWindow. (see 7:19)

    • @Inf4mousKidGames
      @Inf4mousKidGames Před 4 lety

      @@Lelefant_ I did a dumb I named the variable something else 🤣

  • @pedroluzio
    @pedroluzio Před 4 lety

    can you show the contents of "Game Data" ?

  • @theman2636
    @theman2636 Před 4 lety +1

    This is kinda old now why don't you make a video on the same subject but with UIElements

  • @ruchirraj5300
    @ruchirraj5300 Před 3 lety

    Please make some more editor tool windows

  • @wombatbat6955
    @wombatbat6955 Před 4 lety

    How come I'm only now finding about this channel? This is Brackeys level tutorial!

    • @TheAdeOfSpades
      @TheAdeOfSpades Před 3 lety

      Brackeys is for excitable noobs.
      This is next level.
      Not many make it to the next level.

  • @Shonnyy
    @Shonnyy Před 3 lety

    "Change these fuckers" lol

  • @excelion7109
    @excelion7109 Před 3 lety +2

    If only GameDataObject was shown for a single frame... but nope.

  • @jibbyis_2327
    @jibbyis_2327 Před 3 lety

    MY BRAIN HURTS SO MUCH FROM JUST 10 MINUTES

  • @emo666man122
    @emo666man122 Před 3 lety

    10000000000 menu's and all i want is a search button.

  • @Momonyaro
    @Momonyaro Před 4 lety

    b r u h