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. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    You should be able to access the property's value entry and get a reference to your parent class that way:
    Code (CSharp):
    1. public class SomeMonoBehaviour : MonoBehaviour
    2. {
    3.     // [...]
    4. }
    5.  
    6. public class SomeMonoBehaviourProcessor : OdinAttributeProcessor<SomeMonoBehaviour>
    7. {
    8.     public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member, List<Attribute> attributes)
    9.     {
    10.         var someMonoBehaviour = (SomeMonoBehaviour)parentProperty.ValueEntry.WeakSmartValue;
    11.      
    12.         // [...]
    13.     }
    14. }
     
    Neohun likes this.
  2. Neohun

    Neohun

    Joined:
    Oct 30, 2018
    Posts:
    77
    Thank you so much!
    May I ask a few quick questions for the custom editor window that I create with Odin:
    1 - Custom context menu is awesome but I don't want to allow copy paste, copy to clipboard and set null, which breaks the whole system if it is used accidently which comes as default I have to disable them because I have a complex editor system which has lots of nested objects, list inside table list inside another list etc. and I need to allow only my custom context menu which has delete and rename only for some sections.. [DisableContextMenu] attribute is disabling all context menu, is there any option to disable it for some properties without losing my custom context menu? also applying for every property in a class is really annoying is there a disable option for the whole class but allow only for some field/properties..

    2 - How can I refresh the editor to update the changes immediately because till I move my mouse it doesn't update with some attributes such as [OnValueChanged] I have a workaround though I call Editor.Forcus() func when I complete my run in the func is there any better option, am I missing something?

    3 - Is there any chance that you can implement a horizontal list like table list but rather than vertical, it draws the elements horizontal next to each. I was making a translator window and since there was a limited amount of languages (only the major languages) I have created a field for each other, that'll do for me for now so I ask for future implementations whether you can achieve something like this or not..

    4 - This one is more of a suggestion actually, can you implement a horizontal line (draws a colorful line only) and a [SingleEnumSelect] attribute which allows only one selection for flags enums rather than multiple.. I have implemented my own attribute which works quite well but I guess since it is very easy to implement you can add two more useful attribute to your system which I'm a huge fan by the way I have started a few days ago and it is a must have when we consider how terrible unity's custom editor system, it makes it much more fun and organized.. I'm always against the 3rd party assets which I never use to not have a dependency on them because I don't trust for stability and long term support but since this is an editor asset not runtime I have tried for the first time and this is very well documented and well organized although it needs some improvements for some advanced customizations but still very very good.

    The first question what matters the most actually the others just nice to have :)
     
    Last edited: Oct 30, 2022
  3. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    275
    hello eveyone,a stupid question here,
    Can I use odin without attributes workflow?because I don't want to add editor attributes to my runtime code.
    I mean is there anyway that i can write a editorwindow class and call odin's ui component?
     
  4. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    A lot of Odin's more complicated drawers do not have simple methods that you can just call to draw them, so at some point in the process you're always going to use attributes. Odin has something called AttributeProcessors that allows you to apply attributes to your members programatically which makes it possible to separate your runtime code from your editor code while still using attributes.
     
  5. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    505
    Hi there, Didn't find the answer in thread.
    Is there a way to display an animation / clip preview in an Object Preview (or anything) ?
    This is what I get so far :
    upload_2022-11-18_15-34-15.png
     
  6. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    505
  7. epare025

    epare025

    Joined:
    Oct 9, 2017
    Posts:
    10
    Saw that this asset has issues working with nested prefabs, what are the limitations of odin inspector's compatibility with nested prefabs? What can't I do and how is the nested prefab workflow affected by Odin's lack of support?

    I got Odin before knowing this and am wondering if this asset is of any use since I very much like to use nested prefabs.
     
  8. Schwapo

    Schwapo

    Joined:
    Jul 29, 2019
    Posts:
    10
    Odin Inspector works perfectly fine with nested prefabs, it's Odin Serializer that does not.
    This means that if you use one of Odin's serialized classes like SerializedMonoBehaviour or SerializedScriptableObject you may get weird and unexpected behaviour with prefabs. If you use Unity's default serialisation you should be fine. We're also currently working on a solution to this that could reintroduce full support for prefabs, there is no guarantee since we tried it a few times without success, but it seems to be promising so far.
     
  9. wechat_os_Qy07oG6LBuLwxrt0ao4ZkEwPc

    wechat_os_Qy07oG6LBuLwxrt0ao4ZkEwPc

    Joined:
    Jun 28, 2021
    Posts:
    17
    hi, I have some class Use unity CustomEditor but want to Drawn by odin. How should I Do?
    And I not want to change the class Editor Becouse It's from third party Plug.
     
    Nintendo-Silence likes this.
  10. Torukun_404

    Torukun_404

    Joined:
    Dec 14, 2021
    Posts:
    12
    sorry for my poor English if i make any mistake :)

    Hi, I just get started with Odin inspector, I've tried some attribute in the documentation, But I just encounter a problem.
    None of any attribute work as expected within non monobehavior class at all. But work just fine in when I use them within mono class. Here are some pictures.

    within non mono:
    Unity_1xFdnUaTKR.png

    within mono:
    Unity_vl3nkmTXCo.png

    The code:
    rider64_EJRS6vMq0Y.png
     
  11. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Try removing the
    [Serializable]
    attribute from the class. From my experience (with an older Odin version), Odin ignores classes with that attribute.
     
    Torukun_404 likes this.
  12. Torukun_404

    Torukun_404

    Joined:
    Dec 14, 2021
    Posts:
    12
    I'm currently using Odin v3.1.9, will this bug gone if I try update the package? Also do the class still serializable without
    [Serializable] attribute or there are other ways around?
     
  13. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    I think (but don't know) Odin sees the Serializable attribute and decides that Unity should be responsible to serialize this class. At the same time, it is part of a SerializedMonoBehaviour which is drawn by Odin. I am not sure if the class is actually serialized by Unity then. At least it is not correctly drawn by Odin.

    Odin Serializer will be able to serialize the class without that attribute. Other serializers might ignore it.

    Anyway, I just tell you my observations and my best guesses about the technical details. I guess @Schwapo or an Odin developer can give you a better answer here (I'm also curious).
     
    Torukun_404 likes this.
  14. asqewfcq2egf

    asqewfcq2egf

    Joined:
    Nov 16, 2018
    Posts:
    15
    how do i make [Button] stop dirtying the scene? even a simple Log() call is dirtying it.
     
  15. RedZAndroidDev

    RedZAndroidDev

    Joined:
    Dec 2, 2016
    Posts:
    7
    Here is a useful video for someone who is new to Odin:
     
    ledshok likes this.
  16. rioneye

    rioneye

    Joined:
    Aug 10, 2015
    Posts:
    12
    Hi,

    I'm getting a few errors while building my app on Android that I have no idea how to debug:

    Code (CSharp):
    1. ArgumentNullException: Value cannot be null.
    2. Parameter name: unityObject
    3. Sirenix.Serialization.UnitySerializationUtility.SerializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, System.Boolean serializeUnityFields, Sirenix.Serialization.SerializationContext context) (at C:/Sirenix/OdinSerializer/OdinSerializer/Unity Integration/UnitySerializationUtility.cs:592)
    4. Sirenix.OdinInspector.SerializedMonoBehaviour.UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize () (at C:/Sirenix/OdinSerializer/OdinSerializer/Unity Integration/SerializedUnityObjects/SerializedMonoBehaviour.cs:44)
    5. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    Code (CSharp):
    1. ArgumentNullException: Value cannot be null.
    2. Parameter name: unityObject
    3. Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context, System.Boolean isPrefabData, System.Collections.Generic.List`1[T] prefabInstanceUnityObjects) (at C:/Sirenix/OdinSerializer/OdinSerializer/Unity Integration/UnitySerializationUtility.cs:1371)
    4. Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context) (at C:/Sirenix/OdinSerializer/OdinSerializer/Unity Integration/UnitySerializationUtility.cs:1360)
    5. Sirenix.OdinInspector.SerializedMonoBehaviour.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize () (at C:/Sirenix/OdinSerializer/OdinSerializer/Unity Integration/SerializedUnityObjects/SerializedMonoBehaviour.cs:37)
    6. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    I have several scripts that use
    SerializedMonoBehaviour
    but I don't know which is the offending script or object. Has anyone run into these before?
     
  17. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Odin is using [CustomEditor( typeof( Object ), true )] to handle a number of custom things, I think including the Button attribute which is conflicting with some custom editors of our own. Is there any way to get them to co-exist? We could even create a base class with events and have Odin subscribe to it or something similar
     
  18. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    186
    Odin does not in fact use that approach - though in practical effect it does do something similar. Odin decides itself which types it wants to draw, and then it directly injects itself into Unity's internal editor mappings to set itself as the editor for all types it wants to target. It just so happens that the setup of things Odin will choose to inspect by default looks a lot like a [CustomEditor(typeof(Object), true)] setup - if Odin detects that a type already has a custom editor, Odin will respect that and leave the type alone so as not to interfere with its custom drawing.

    What you can do to implement Odin is inherit from OdinEditor instead of Editor if Odin is installed, checked via for example a preprocessor directive like #if ODIN_INSPECTOR - then all the base editor drawing methods such as OnInspectorGUI will draw Odin's inspector instead of Unity's default.
     
    Nihil688 likes this.
  19. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Odin lives inside the plugins folder where my dll/framework is inside packages so it will always work above mine. I guess your suggestion might work but since the default result is that it does actually not recognize my class currently unless there's a setting somewhere?
     
  20. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    It didn't work unfortunately:


    Code (CSharp):
    1.  [CustomEditor( typeof( Object ), true )]
    2. #if ODIN_INSPECTOR
    3.     internal class CustomObjectEditor : Sirenix.OdinInspector.Editor.OdinEditor
    4. #else
    5.     internal class CustomObjectEditor : UnityEditor.Editor
    6. #endif
    7. {
    8.     public static event Action<object> OnInspectorGUIAction;
    9.     public override void OnInspectorGUI()
    10.     {
    11.        base.OnInspectorGUI();
    12.  
    13.        if( OnInspectorGUIAction != null )
    14.        {
    15.           OnInspectorGUIAction( target );
    16.        }
    17.     }
    18. }
     
  21. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    93
    Hello, one item in the initial todo list was the ability to have serialized Object snapshots. Would be a cool feature to have these snapshots exposed directly in inspector, without additional files in the project, and be able to apply them to existing components at editor and runtime. Any updates on this or ideas on how implement this?
     
  22. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    I'm not a hundred percent sure what your intentions are. But I have an Editor Extension in the making you might be interested in: It allows you to bind (almost) any value of a component or game object (or any variable in your code) to something I call "Brush". You can then have multiple sets of values (I call them "Themes") to apply a value (a "Paint") to it.
    If this is what you need, write me a PM. I may send you a beta version if this is something useful for you (you already beta tested my asset Beter UI for me some years ago, hope you still find it useful) :)
     
    Grumpy-Dot likes this.
  23. growingmaster

    growingmaster

    Joined:
    Dec 20, 2020
    Posts:
    3
    Hello, I met some problems regarding data saving. I have a list of classes with polymorphism, and I want to save different categories of classes into different format(not DataFormat).
    For instance, I have an abstract class A. Now there are two classes, B and C, inherit A. B has two fields to save while C has three fields. I can use a field to identify the type. And I was wondering if there's any approach to make odin serializer recognize that and save it, just like the type filter attribute does?
    The only way I have for now is have a data class with some field named "field1", "field2" and I need to parse them according to type after deserialization, which might lead to a great amount of unnecessary memory usage.
     
  24. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    Can you elaborate on what you mean by this?

    If polymorphic serialisation is in effect, then Odin will serialise and draw the correct type and all its respective serialisable members.
     
  25. growingmaster

    growingmaster

    Joined:
    Dec 20, 2020
    Posts:
    3
    My concern is about saving and loading. Odin can definitely serialize all the child classes correctly. But when it comes to the process of deserialization, how can it recognize what kind of child class it should be when facing a string of binary? We only have "List<A>" for the deserialization utility.

    I admit I haven't tried it yet. But I guess the basic SerializationUtility.DeserializeValue<T> as written in the sample is not enough to deal with that.
     
  26. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    It handles polymorphic and by-reference serialisation fine. There's nothing extra you need to do.
     
  27. growingmaster

    growingmaster

    Joined:
    Dec 20, 2020
    Posts:
    3
    Cool, thank you. I would try it then.
     
  28. HajiyevEl

    HajiyevEl

    Joined:
    Feb 19, 2020
    Posts:
    46
    Hi. How can i make [ListDrawerSettings(CustomAddFunction)] work with [TableList] ?
    They work separately, but not together.
    I mean, if list is drawn as a table and i add element, than 'CustomAddFunction' will not fire.
    And if i disable table view and add element, 'CustomAddFunction' will fire.

    Also, about HideInheritedChildProperties. Is there any way for same logic to be applies to fields?
    Also, ListDrawerSettings(OnTitleBarGUI = "DrawRefreshButton") does not work when list is drawn as table [TableList] (refresh button doesnt show up), but works if table view disabled (refresh button shows up).
     
    Last edited: Mar 19, 2024
  29. frank231love

    frank231love

    Joined:
    Jun 2, 2019
    Posts:
    22
    "Odin Serializer ArchitectureInfo initialization with defaults (all unaligned read/writes disabled). Odin Serializer detected non-white-listed runtime platform IPhonePlayer; disabling all unaligned memory read/writes. libc++abi: terminating due to uncaught exception of type Il2CppExceptionWrapper

    I am currently using: Odin version: 3.1.14.3 Unity version: 2022.3.10 Encountering this issue, how should I handle it? Now encountering this issue when publishing to Xcode."
     
  30. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Try to change the Api Compatibility Level in the player settings (from .Net Standard to .Net Framework). This solved a similar issue I encountered.
     
  31. frank231love

    frank231love

    Joined:
    Jun 2, 2019
    Posts:
    22
    thank you
     
  32. HajiyevEl

    HajiyevEl

    Joined:
    Feb 19, 2020
    Posts:
    46
    Hi! How can i enable scrollbar when list is TableList with ReadOnly attribute added? Scrollview bar gets locked and impossible to scroll.
    Screenshot 2024-03-26 113303.png

    P.S. I don't want Add or Delete buttons to be shown.

    EDIT: Solved.
    Removed [ReadOnly] attribute from parent list that had [TableList] attribute.
    Added 'isReadOnly' param to parent list that had [TableList] attribute.
    Added [ReadOnly] attribute to variables of parent list's members.
    Changed [ReadOnly] attribute to 'isReadOnly' param on child list that had [TableList] attribute.
     
    Last edited: Mar 26, 2024 at 10:27 AM