Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Odin Inspector & Serializer - The Ultimate Workflow Tool ★★★★★

Discussion in 'Assets and Asset Store' started by jorisshh, Jun 15, 2017.

  1. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Love your Editor toolset. I have one thing I would like to do but do not see the way to get it to happen. Say I get a List of Directory Paths and do not know whether that is 1 or 25 and want to create buttons to handle the loading of the assets in the directory. The only way i can see is to make a few dozen functions with a [Button] attribute with a {HideIf(*condition)] attribute to turn off any buttons over the List count value. What are your suggestions? I am sure I am not the only one ever wanted varied amount of buttons based on a List count.
     
  2. Tarodev

    Tarodev

    Joined:
    Jul 30, 2015
    Posts:
    190
    I'm making a simple grid game and would love to make my levels directly on a scriptable object.
    How would I display a 10x10 grid of squares in the inspector, which could either be clicked multiple times to change the tile, or drag/drop onto them?
     
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Apparently the brilliant author of this tool expects us to go to free speech banning discord to ask him questions.
     
    Romeno likes this.
  4. WryMim

    WryMim

    Joined:
    Mar 16, 2019
    Posts:
    69
    Hi, I wrote my implementation of SerializableDictionary : IDictionary and SerializableDictionaryDrawer : PropertyDrawer, but Odin Inspector is trapping and drawing its own version of Dictionary, how can I disable this? What would make Odin Inspector work EVERYWHERE except Dictionary?
     
  5. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    https://odininspector.com/tutorials/serialize-anything/serializing-dictionaries

    this works just to show in inspector

    ON RUNNING PROJECT ALL DATA ARE GONE !

    https://bitbucket.org/sirenix/odin-inspector/issues/430/dictionary-of-string-and-serialized
    problem solved in 2017 and BACK IN 2021 !!

    any help on this ?


    my steps:

    1. create a new script with the code provided by ODIN, so I can inherit the serialization and dictionary creation

    2. create a new script to use that:

    Code (CSharp):
    1. public class someClass : MonoBehaviour
    2. {
    3. [Serializable]
    4.     public class StringScriptableObjectDictionary : UnitySerializedDictionary<string, List<GameObject>> { }
    5.     public StringScriptableObjectDictionary StringDICT;
    Thing is that even if it shows in inspector and i populate in editor, on RUN = bye bye data.
    fields are serialized and i even tried it with serilaizedfiled on that public stringdict (even if it is allready in the file on point 1) ...

    I am no expert and I am blocked here ... any help would be great .. ty
     
    Last edited: Feb 22, 2021
  6. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    hello, i am wondering how to have a list of items with toggle next to each of them and to force only one to be selected at the time, like a radio button, is something like that built in? i was going through attributes and it seems i have missed something.

    thank you!
     
  7. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    also using ValueDropdown with list of string that are urls and start with "https:\\" i have strange behavior in dropdown (i believe it's intended) i ger sub menues that are forced with backslashes. how to treat string as is?

    thanks you
     
  8. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    I have a ScriptableObject called Ability that contains a list of AbilityComponent. AbilityComponent derives from
    MonoBehaviour so when I make an Ability and add an AbilityComponent to the list, the variables in AbilityComponent are not visible in the inspector.

    Is it possible to use Odin to expose the variables to the inspector?

    I'm using Sirenix.OdinInspector and have added [InlineEditor] above both the Ability and AbilityComponent classes.
    I've changed ScriptableObject in Ability to SerializedScriptableObject and MonoBehavior to SerializedMonoBehaviour in AbilityComponent. But so far nothing is showing.
     
  9. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    I'm running into an error every time I interact with any inspectors that Odin changes. I'm using 3.0.4.0:

    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. Sirenix.OdinInspector.Editor.Drawers.OnInspectorGUIAttributeDrawer.DrawPropertyLayout (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/OnInspectorGUIAttributeDrawer.cs:54)
    4. Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
    5. Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
    6. Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
    7. Current IMGUI event: KeyUp
    8. Odin Property Path: InternalOnInspectorGUI
    9. Odin Drawer Chain:
    10. > OnInspectorGUIAttributeDrawer
    11. > DefaultMethodDrawer
    12. > CompositeDrawer.
    13. UnityEngine.Debug:LogException(Exception)
    14. Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:866)
    15. Sirenix.OdinInspector.Editor.InspectorProperty:Draw() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:677)
    16. Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60)
    17. Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    18. Sirenix.OdinInspector.Editor.Drawers.FixBrokenUnityObjectWrapperDrawer`1:DrawPropertyLayout(GUIContent) (at Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/FixBrokenUnityObjectWrapperDrawer.cs:41)
    19. Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
    20. Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:789)
    21. Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:485)
    22. Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:389)
    23. Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:93)
    24. Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:216)
    25. Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at X:/Repositories/sirenix-development/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:85)
    26. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
    27.  
    28.  
    The Serialization Debugger window also isn't working at all:


    This happened when I backed up my project to test a future version of Unity. When I switched back and checked out my original branch, this started happening. I would have thought everything Odin uses is in Assets folder and is thus protected by version control.

    Can you help me keep these errors from clogging up my console?
     

    Attached Files:

  10. IggyZuk

    IggyZuk

    Joined:
    Jan 17, 2015
    Posts:
    43
    Hello, would anyone be able to show me how to use the OdinEditor to draw an object either as a single property or an array depending on the number of elements?

    Example:
    Code (CSharp):
    1. public class MonoElements : MonoBehaviour
    2. {
    3.     public int[] elements;
    4. }
    5.  
    6. [CustomEditor(typeof(MonoElements))]
    7. public class CustomOdinEditor : OdinEditor
    8. {
    9.     public override void OnInspectorGUI()
    10.     {
    11.         var tree = this.Tree;
    12.         var obj = this.target as MonoElements;
    13.        
    14.         // obj.elements.Length <= 1
    15.         // Draw property, otherwise draw list.
    16.     }
    17. }
     
  11. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Is there a way to change the alternating background color shades used in collection items? It's really difficult with complex data in lists to tell where one item starts and the next one ends as the color variation is too subtle.

    It seems this behavior is built into Unity itself, but though I'd ask.
     
  12. oliver_unity892

    oliver_unity892

    Joined:
    Oct 28, 2019
    Posts:
    91
    Hi. I just quickly need to serialize a couple of two-dimensional arrays or even dictionaries.

    I'm assuming Odin can help me do this easily, or is it overkill?
    Olly
     
  13. IggyZuk

    IggyZuk

    Joined:
    Jan 17, 2015
    Posts:
    43
    It can, check out the examples.
     
  14. dbordzo

    dbordzo

    Joined:
    Aug 14, 2015
    Posts:
    34
    Hello, someone tried to draw property of Better Event in Custom Inspector?
    I have something like that in my class which inhert from OdinEditor:

    Code (CSharp):
    1. EditorGUILayout.PropertyField(BetterEventProprty);
    But it shows at this way, so you can not edit it:

    Thank you in advance for any help
     
  15. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    Does this tool support "Generic Interface" and "Generic MonoBehaviour/ScriptableObject" serialization?
    i.e.
    Code (CSharp):
    1. public interface ITask<T>
    2. {
    3.    void Execute(T t);
    4. }
    5.  
    6. public Controller<T> : MonoBehaviour
    7. {
    8.   [SerializeReference]
    9.   List<ITask<T>> tasks;
    10. }
    11.  
    12. public ControllerAsset<T> : ScriptableObject
    13. {
    14.   [SerializeReference]
    15.   List<ITask<T>> tasks;
    16. }
     
  16. Arkasis

    Arkasis

    Joined:
    Nov 22, 2010
    Posts:
    61
    Hi there,
    I'm in trubble trying to use a "OnValueChanged" attribute on a variable using its own "OdinValueDrawer".
    It just doesn't work.
    Did I miss something or is it not supported?
    Thanks
     
  17. Muhammad_Taha

    Muhammad_Taha

    Joined:
    Jun 21, 2015
    Posts:
    22
    Hi there, any idea how to get selected item in the 2d array?
     
  18. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    Hi Everybody, any idea how to always unfold serialized classes? Is there any attribute, I want PromptData to always be unfolded and be always visible?
    upload_2021-12-14_15-0-37.png
     
  19. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    943
    [InlineProperty] should do that (probably in combination with one of the Group attributes)
     
    pixel_maniacs likes this.
  20. matthewhxq

    matthewhxq

    Joined:
    Jul 6, 2015
    Posts:
    21
    Is there any plan to add drawers for addressables?
     
  21. bconstantin

    bconstantin

    Joined:
    Feb 4, 2019
    Posts:
    15
    Hello, we have a very disturbing bug with Odin serialization. it appears referencing gameobject component prefab lead to a dirty object in scene.

    See my 2 screenshot, one for the prefab, another for the intantiated scene object. Odin think Transform is another value than prefab because referencing the in scene object. Which is NOT the case. It has to treat it like Unity does: no dirty value if the value reference "the same think as the prefab".

    Does someone has a quick fix for it ?
     

    Attached Files:

  22. bconstantin

    bconstantin

    Joined:
    Feb 4, 2019
    Posts:
    15
    Ok seems, SerializeReference is the way ?
    Can someone tell me the truth ? :p
     
  23. bconstantin

    bconstantin

    Joined:
    Feb 4, 2019
    Posts:
    15
    No one really ?
    Found it was good with SerializeReference but Unity has another limitation which break more the serialization than Odin does.
    I'm just blocked by this. Whatever component serialized by Odin on prefab result in dirty variable in scene.
     
  24. EgoJacky

    EgoJacky

    Joined:
    Aug 15, 2017
    Posts:
    28
    Short question, is it possible to access the colors in a colorPalette via script? I want to give a GameObject a Random color from a colorPalette.
     
  25. william_feilangyue

    william_feilangyue

    Joined:
    Nov 2, 2021
    Posts:
    8
    hey guys ,did odin support unity particle system serializer and deserializer?
    +1
     
    Last edited: Jul 5, 2022
  26. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    Yes, you can access all color palettes via:
    Code (CSharp):
    1. Sirenix.OdinInspector.Editor.ColorPaletteManager.Instance.ColorPalettes
     
    EgoJacky likes this.
  27. Oniros88

    Oniros88

    Joined:
    Nov 15, 2014
    Posts:
    150
    Any time I save a script that contains Odin inspector stuff my editor gets spammed with empty game objects and this error as long as I am visualizing the asset in the inspector

    upload_2022-6-18_0-31-6.png

    I have to restart the editor for this to stop happening.
     
  28. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    I guess you're using Unity 2022.2.x? We're aware of this issue and are trying to open an issue with Unity so they can fix it on their end. Right now we would have to dance around the issue and fix it in a way that would probably break in the future.
     
  29. Oniros88

    Oniros88

    Joined:
    Nov 15, 2014
    Posts:
    150
    Yes its that version. Thanks for addressing it.
     
  30. alexandergikalo

    alexandergikalo

    Joined:
    Oct 24, 2019
    Posts:
    19
    Hi.
    Please help me with interfaces.
    Problem: I have ScriptableObject with List<IInterface> field and other ScriptableObject, that inherited ScriptableObject, IInterface. I Want to add objects to list, but incpetor hide it(
    SerializeReference is not a decidion, because it cant link existing scriptableObjects(
     
  31. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    Instead of inheriting from ScriptableObject inherit from SerializedScriptableObject

    Code (CSharp):
    1. public class SomeScriptableObject : SerializedScriptableObject
    2. {
    3.     public List<IInterface> SomeListOfIInterface = new();
    4. }
     
    alexandergikalo likes this.
  32. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    208
    I have some auto-generated scriptable objects that are created by Photon's Quantum. They are partial classes that are defined partially in the Quantum namespace and can be extended with partial classes in Unity. I am unable to use Odin on the partial classes in Unity for buttons and other attributes. In the Odin preferences I don't have the option to override the class.

    Is there a workaround where I can override the CustomEditor for a class, then allow Odin functionality in the partial class? Looks like I might be able to create my own OdinEditor for the class...but can't disable that either.

    upload_2022-7-29_14-18-45.png
     
  33. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    Photon defines a custom editor for the shown types. Odin does not override existing custom editors unless you specifically create a new class that derives from OdinEditor and add the CustomEditor attribute to it. However, doing this will override Photon's editor completely, and you will have to re-implement any custom functionality that they added in their custom editor.
     
  34. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    653
    Hi.

    I'm trying to use a variable for the MinMaxSlider atribute but get an error message.

    Cannot convert source type 'string' to target type 'float'

    2022-07-30 21_10_11-Shooter_2041 – DataDisplay.cs.png

    Is the documentation up to date?

    Edit: I tried to reproduce the bug and its seems to be limited to my project. Let me know if it rings a bell to anyone.
     
    Last edited: Jul 30, 2022
  35. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    208
    Great. Thanks for the advice. I’ll give it a shot and see how much trouble I can get in.
     
  36. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    The documentation is up do date. There are only 3 things I can think of.

    1. Your IDE is just messing up and can't seem to find the right overload. In this case it should still work in Unity though.

    2. You have another MinMaxSlider attribute from some other asset or script. Make sure it's the right one.

    3. You're using an old Odin version that doesn't have this overload. However, that's pretty unlikely since you would have to be below Odin 2.0.0. To be sure check your Odin version by navigating to
    Tools > Odin Inspector > About
    .
     
    Marc-Saubion likes this.
  37. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    653
    Thanks for the suggestions but it's neither of these 3. I have the latest Odin on the latest Unity editor LTS and it doesn't work in the editor.

    The broken feature is the one to use an other variable in an attribute. It's not limited to the MinMaxSlider.

    2022-08-01 04_54_42-Window.png 2022-08-01 04_55_23-Window.png
     
  38. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    There is no feature like that. The Range attribute you are showing is a Unity attribute. Odin doesn't have a feature that allows you to pass in strings as value replacements for all attributes, that only works for Odin attributes since they have overloads that take in a string which Odin can then resolve into a valid value.

    However, you can use Odin's PropertyRange attribute which works identical to Unity's Range attribute while allowing for resolved values.
     
    Last edited: Aug 4, 2022
    Marc-Saubion likes this.
  39. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    653
    You were right all along, it was an other MinMaxRange attribute and I was distracted by the wrong use of the Range one from Unity.

    I renamed the other MinMaxRange and it works.

    Thanks a lot for your help.
     
  40. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    Unity_mCtt0mlfRh.png

    I have a 'Type Mismatch' label on all my components in a List. Is there any way I can get a better label?
     
  41. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Does this happen when you inspect multiple objects at the same time, or does it also happen when you're only looking at the one object?
     
  42. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    upload_2022-8-22_12-11-23.png

    If I make a second scriptable object and select them both, it just shows this.
    Is the problem caused because these are scene gameobject references rather than assets?
     
  43. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Yeah, the type mismatch means that the two objects you've selected don't have the same type of list elements, so Odin doesn't know which drawer to be using. The length of each list is also different, in your second screenshot.

    What is the type definition of the all points field?
     
  44. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    [SerializeField] private List<SnapplePoint> allPoints; 


    This is in my scriptable object. Nothing fancy.
    SnapplePoint is just a monobehaviour.

    If I tap the mismatch it pings the correct object, and it behaves fine in code, but the inspector label is broken. I haven't selected multiple objects so I don't know what the match complaint is about.
    upload_2022-8-22_13-34-25.png
     
  45. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    That's very odd. From the looks of it, SnapplePoint is not a MonoBehaviour, otherwise it would have a normal object field. What happens if you disable Odin in the preferences, how does Unity draw it?

    Are you using an older beta version by any chance? We did have an issue that could have caused that in one of the beta releases, it got fixed quickly.
     
  46. mfakkaya

    mfakkaya

    Joined:
    Mar 19, 2016
    Posts:
    21
    no reorderable dictionary? this is so sad :( lists have it but not dictionary. does anyone know a way to add it? or is odin not available for it? (simply)
     
  47. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Dictionaries are inherently unordered and not reorderable, that's one of the prices you pay for getting the fast key lookups they provide. Sortable dictionaries do exist, but in order to make them reorderable, you'd have to serialize the order somewhere.

    I'd recommend going with a list and make your own Key Value pair struct, then turn that into a dictionary at runtime if needed. You can use the [ValueDropdown(IsUniqueList = true)] to help ensure they are unique.
     
  48. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    Turning off the Odin helped me realise it was my own mistake! Thanks for the tip!
    I thought that ScriptableObjects could reference scene objects, but they cannot.
     
    bjarkeck likes this.
  49. Neohun

    Neohun

    Joined:
    Oct 30, 2018
    Posts:
    77
    Hi guys,
    I have a question about "Custom Attribute Processors" my question is very straightforward how can I access to the instance class from the custom processor? I need to reach an enum value of my class to hide or show some items of the list based on that value and all I need is to reach the parent class so I can use "member.GetValue(object)" func.. it drives me crazy and I'm not sure whether it is possible or not.. any help is appreciated..
     
  50. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello everyone!

    Is it possible to access the Unity preferences in an Odin editor? I would like to add the "External Tools" page in "Edit -> Preferences..." in my own editor window to provide a shortcut for those settings, but could not yet find a way to show them in an editor window.

    Any tips and pointers would be greatly appreciated.

    Thanks in advance,
    Patrick