Search Unity

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

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

  1. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    I've gone through all three of the demo scenes. There's a value dropdown example but I wasn't able to find an example where you could multi-select items in a dropdown list except for the LayerMask variable.
     
  2. williamian

    williamian

    Joined:
    Dec 31, 2012
    Posts:
    119
    I may be wrong. Just re-read your post and saw the multi-select, so that may not be an option in that case. I am sure they will respond with a definitive answer though.
     
    bjarkeck likes this.
  3. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    Sorry to be flooding this thread, but I've got another question:

    I have a script called script_B (type Monobehavior) that I want to be embedded into another script script_A. By embedding, I mean I want all inspector variables for script_B to show up in script_A.

    I also want to be able to add in multiple script_B's into script_A, like how elements of an array could be added and removed in Odin.

    How do I do this? Cheers
     
  4. Tamino

    Tamino

    Joined:
    Apr 15, 2013
    Posts:
    9
    To add to this, Odin is causing another Unity addon called Behaviour Machine to throw the same error when trying to add nodes to an ActionState, and it prevents some of the menus from coming up when trying to edit a behaviour tree...

    The error in the quoted message is also happening on Unity 2017.1.1f1.
     
  5. Tamino

    Tamino

    Joined:
    Apr 15, 2013
    Posts:
    9
    Just FYI, this problem is not limited to the About box in Unity. It's breaking other stuff as well. See my post here.
     
  6. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Thanks for narrowing it down. I'll have a look at that.

    You can drag and drop all array and list elements, even between lists and windows. Hope I understood your question right correctly :)

    Could enum-bitmasks maybe work for you? They also have support for multi-selection, just like LayerMasks. Not sure if that would work for you? Alternatively, you could do something like this:

    Code (CSharp):
    1.     private static string[] source = new string[] { "a", "b", "c", "d" };
    2.  
    3.     [SerializeField, HideInEditorMode]
    4.     private List<int> selected;
    5.  
    6.     [OnInspectorGUI]
    7.     private void DrawMultiSelectList()
    8.     {
    9.         SirenixEditorFields.Dropdown("Selected", this.selected, source, true, null);
    10.     }





     
  7. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    Technically, these are errors in their respective products, which do not take into account the fact that a dynamic assembly may be loaded in the current AppDomain. Odin declares dynamic assemblies, to provide emitted type formatters that drastically speed up its serialization.

    The Behaviour Machine issue we unfortunately can't do anything about - the author of Behaviour Machine will have to fix it on his end.

    The error in Unity, we had a while back, and tried to fix on our own by using Reflection to call into Unity's About window utilities before we define any dynamic assemblies, thus causing some data to be cached. This means it doesn't hit this error if the data is requested later. This has seemed to work for a while, and I'm unable to figure out, so far, why it's back.

    I have been trying to replicate the About Unity window breaking in various versions of 2017.1 and 2017.2 (on Windows 10), and so far I simply haven't been able make it happen no matter what I do. I'll continue investigating this, though. Out of curiosity, which target platform do you have set in the editor when this bug occurs?
     
  8. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    No problem at all! It sounds to me like you are describing exactly what the InlineEditor attribute does:

     
    recon0303 likes this.
  9. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    This seems to be what I'm needing. Thanks so much!
     
    bjarkeck likes this.
  10. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    It seems like the InlineEditor attribute only supports Unity components rather than for scripts written by the user. :(
     
  11. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Ah, sorry for not understanding you correctly. Everything else except unity assets are already drawn directly in the inspector if they are serialized or decorated with a ShowInInspector attribute. So there shouldn't be any need to use the InlineEditor, if it's not a Unity object. Are you maybe looking for the ShowInInspector attribute? or maybe the HideLabel or the InlineProperty in order to inline already drawn types? Or maybe you could show the reference via a property using ShowInInspector?

    If you could share some example code, showing what wish to achieve, that would help a lot.
     
  12. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    Is it possible to have Odin work together with custom editor scripts?

    I am using
    Code (CSharp):
    1. EditorGUILayout.PropertyField(something)
    in my custom editor script in order to show something if another variable is set. I'm doing it this way on purpose without using Odin's [ShowIf] attribute. I do not wish to use [ShowIf] for this implementation.

    Is it possible to have Odin work with custom editors?
     
  13. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    This is possible, yes - you should in this case inherit from OdinEditor instead of Editor, and then use Odin's own property system to draw instead of Unity's. In Odin, the PropertyTree and InspectorProperty types correspond to respectively Unity's SerializedObject and SerializedProperty types, and provide similar functionality.

    For example, your custom editor might look like this:

    Code (CSharp):
    1. public class CustomOdinEditor : OdinEditor
    2. {
    3.     public override void OnInspectorGUI()
    4.     {
    5.         var tree = this.Tree;                                      // Like this.serializedObject.
    6.         var obj = this.target as MyMonoBehaviour;
    7.  
    8.         InspectorUtilities.BeginDrawPropertyTree(tree, true);      // This and EndDrawPropertyTree automatically handles a lot of stuff like prefab instance modifications and undo
    9.  
    10.         if (obj.SomeCondition)
    11.         {
    12.             var someProp1 = tree.GetPropertyAtPath("someProp1");   // Like serializedObject.FindProperty("path")
    13.             someProp1.Draw();                                      // Like EditorGUILayout.PropertyField(property);
    14.         }
    15.         else
    16.         {
    17.             var someProp2 = tree.GetPropertyAtPath("someProp2");
    18.             someProp2.Draw();
    19.         }
    20.  
    21.         InspectorUtilities.EndDrawPropertyTree(tree);
    22.     }
    23. }
    In fact, you can draw the entire tree "as usual", IE the default Odin inspector, merely by calling tree.Draw(), which draws all the root level properties of the tree - that's basically how Odin renders the default inspector.
     
    AdamAlexander likes this.
  14. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    Thanks for the reply! I'll try this out.

    I've been using Odin for a week now and it's made my life so much easier. Keep up the awesome work!
     
    bjarkeck likes this.
  15. Tamino

    Tamino

    Joined:
    Apr 15, 2013
    Posts:
    9
    Standalone.

    I'm on Windows 10 as well.

    Pretty fresh install of everything as I just built a new computer.

    Odin is unusable for me because of this issue. Who knows what it will break in my project? Not good. I remember trying it out several months ago and I had to remove it from my project then as well, unfortunately. Still hoping to be able to use it someday.

    Uninstalling it was also not straight forward and the uninstall guide is marked as "coming soon." Glad it didn't get embedded too deep into my project before deciding to uninstall.
     
  16. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    I'm sorry to hear that Odin hasn't worked out for you, but I can understand why you made that call. There unfortunately just isn't anything we can do about such bugs in other products than ours. Dynamic assemblies are bog standard .NET fare, and we cannot really help it when other code that we have no control over breaks because it doesn't iterate over loaded assemblies properly. We also can't stop using them - their use is crucial to many core Odin features (fast, garbage-free serialization, fast general reflection for performance, using legacy Unity property drawers to render Odin-serialized data that has no SerializedProperty to ensure full compatibility, and so on).

    Regarding the uninstalling, can you perhaps let us know which parts you found difficult to deal with? Maybe there is something more we can do to make it easier on people, though we have already tried our best. If you delete everything from Odin but the Sirenix.OdinInspector.Attributes.dll file, then the only things that will break are references to non-attribute Odin classes, such as if you've been using Odin's serialization, which you will have to remove from your code manually.
     
    Last edited: Sep 20, 2017
  17. Tamino

    Tamino

    Joined:
    Apr 15, 2013
    Posts:
    9
    If you want your asset to be usable in production it must play well with others, including the Unity editor and any potential other assets. Even if technically the other assets must adapt to something you're doing in the reflection domain that's rarely encountered. I think you should be more proactive in reaching out to other developers to educate them how to fix the issue--they're probably not even aware of it. At least publish some information on how they can fix it, which users who are affected by issues like these can point to in order to encourage others to adapt their code to be compatible with Odin.

    I think the uninstall guide on your website being marked as "coming soon" is particularly something that needs to be addressed as I had to figure out how to recover from using your serialization while needing to uninstall without breaking my project, and luckily it wasn't too deeply embedded as I had only been using it on a couple scripts. However, even after removing it with special attention given to the scripts where I had used it, it still threw a few extra errors in elements of my project where I had not explicitly used it for a while and I wasted a bunch of time getting my project cleaned up.
     
    Last edited: Sep 21, 2017
  18. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Just saw that there is a new version in the asset store (1.0.5.1) and I noticed that the generated dlls are back
    upload_2017-9-20_12-29-30.png

    Do I remember correctly that you actually wanted to get rid of those? I guess then we should exclude those files again from version control? :)
     
  19. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    Odin should delete them the moment you finish importing. Those are just empty dummy assemblies to replace pre-existing generated assemblies, that we added to fix a few errors that Unity threw if we deleted the full pre-existing assemblies. So you don't need to include them when you import.

    So no, it is most definitely not back :)
     
  20. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Ah okay, I was so full of fear I didn't even bother to import ;)
     
  21. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Hey loving the asset. By far best asset I have bought. But I'm not sure if bug or if I'm missing something, but I can't seem to display an object within a serialized class.
    It will display as expected like this:
    Code (CSharp):
    1. public class MyComponent: SerializedMonoBehaviour
    2. {
    3.      public object obj;
    4. }
    but not like this:
    Code (CSharp):
    1. public class MyComponent: SerializedMonoBehaviour
    2. {    
    3.             [Serializable]
    4.             public class Value
    5.             {                                
    6.                 public object obj;
    7.             }
    8. }
    What am i missing? :/
     
  22. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    There's a difference between declaring a type, and declaring a field of that type. You're declaring a class in the second example, not a field. You'd need to do it like this:

    Code (sharp):
    1. public class MyComponent : SerializedMonoBehaviour
    2. {
    3.     // Declare a field containing an instance of the Value class
    4.     public Value myField;
    5. }
    6.  
    7. // Declare the Value class
    8. [Serializable]
    9. public class Value
    10. {
    11.     public object obj;
    12. }
    However, in this case, Unity would still serialize the "myField" field, because it is a class marked as Serializable. Odin will, by default, not serialize a field that it knows Unity will serialize. You either need to not mark the class Serializable, or you need to mark "myField" with the OdinSerialize attribute - in which case, both Odin and Unity will serialize the field, but Odin will override Unity's serialization. Here's some more information about when respectively Unity and Odin serialize your fields and properties.
     
  23. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Thank you that was very helpful.
    I did forget to type in the public field in the post but i do have it in my class. But i had it as a private list.
    I read that page you send me before but after a second go i figured out what i was doing wrong. I had the field taged with [SerializeField] i changed it to [OdinSerialize] (as below) and everything works fine.

    Code (CSharp):
    1. public class MyComponent: SerializedMonoBehaviour
    2. {
    3.     [OdinSerialize]
    4.     private List<Value> values;
    5.            
    6.     [Serializable]
    7.     public class Value
    8.     {      
    9.          public object obj;
    10.      }
    11. }
     
  24. unwitty

    unwitty

    Joined:
    Jan 18, 2015
    Posts:
    31
    Is it possible to have buttons made for methods to appear on top of the script before other BoxGroups? I'm using the order property in the box group but the buttons for the methods still appear at the very bottom.
     
  25. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    You can put the PropertyOrder attribute on the button methods and give them a very low priority to put them on top of your inspector.
     
    DonLoquacious likes this.
  26. Bulwark-Studios

    Bulwark-Studios

    Joined:
    Sep 20, 2013
    Posts:
    18
    Hi,

    I wonder if there is a way to use OdinInspector's drawer for a custom EditorWindow ?
    I found the drawer API like ColorDrawer.DrawPropertyField but not a way to use it.

    Thanks
     
  27. TS42

    TS42

    Joined:
    Nov 7, 2013
    Posts:
    13
    DonLoquacious likes this.
  28. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Yeah, check out Tor's answer for sure :). A slightly modified version that works within an Editor window could look something like this:

    Code (CSharp):
    1.  
    2. public class SomeEditorWindow : EditorWindow
    3. {
    4.     private PropertyTree tree;
    5.  
    6.     public Color DrawThisFieldUsingOdin;
    7.  
    8.     public void OnGUI()
    9.     {
    10.         if (this.tree == null)
    11.         {
    12.             // You can give it any object, and draw its individual members like below.
    13.             this.tree = PropertyTree.Create(this);                              // Like new UnityEditor.SerializedObject(obj);
    14.         }
    15.  
    16.         InspectorUtilities.BeginDrawPropertyTree(this.tree, true);              // This and EndDrawPropertyTree automatically handles a lot of stuff like prefab instance modifications and undo
    17.         {
    18.             var someProp = tree.GetPropertyAtPath("DrawThisFieldUsingOdin");    // Like serializedObject.FindProperty("path")
    19.             someProp.Draw();                                                    // Like EditorGUILayout.PropertyField(property);
    20.         }
    21.         InspectorUtilities.EndDrawPropertyTree(this.tree);
    22.     }
    23. }
    24.  
    Also, in case you didn't know. You can also draw entire editor windows using Odin:
    http://sirenix.net/odininspector/faq/13/can-i-use-odin-inspector-to-create-custom-editor-windows
     
    DonLoquacious likes this.
  29. Bulwark-Studios

    Bulwark-Studios

    Joined:
    Sep 20, 2013
    Posts:
    18
    Thanks for the links ! My editor window will be awesome !
     
    bjarkeck likes this.
  30. EricM

    EricM

    Joined:
    Aug 17, 2013
    Posts:
    10
    First, great asset. Loving the grouping and list/dictionary options. I might be asking too much here, but is it possible to get access to the Color Palettes created in Odin's settings via code? I would like to change which palette is active dynamically and (ideally) change the selected color to the same color slot in the new palette. (i.e. user selects first color from "my blues" palette and then the palette changes to "my oranges." The selected blue color then changes to the first color in "my oranges") Thanks!
     
  31. candycat

    candycat

    Joined:
    Jun 5, 2014
    Posts:
    29
    Great assets!

    Is there any way to display multiple customized curves with fixed ranges in Odin? Like this:
    QQ图片20170928162810.png
     
  32. bjarkeck

    bjarkeck

    Joined:
    Oct 26, 2014
    Posts:
    301
    Hi Eric,

    This is unfortunately not possible at the moment. But I'll polish it up a bit and make the API public today. So you will be able to create, modify and delete color palettes from script in 1.0.5.2 which we'll be submitting to the Asset Store soon.

    Great suggestion. How about something like this?

    Code (CSharp):
    1. [ColorPalette("$CurrentColorPaletteName")]
    2. public Color MyColor;
    3.  
    4. public string CurrentColorPaletteName { get { return someCondition ? "Blues" : "Oranges"; } }
    5.  

    Not currently no, but it's a good suggestion as well :) We might add that. Here is how it could look

    Code (CSharp):
    1. public class SomeComponent : MonoBehaviour
    2. {
    3.     [AnimationCurveRange(1, 1)]
    4.     public AnimationCurve SomeCurve;
    5. }
    6.  
    7. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
    8. public class AnimationCurveRangeAttribute : System.Attribute
    9. {
    10.     public readonly int X;
    11.     public readonly int Y;
    12.     public readonly int Width;
    13.     public readonly int Height;
    14.  
    15.     public AnimationCurveRangeAttribute(int x, int y, int width, int height)
    16.     {
    17.         this.X = x;
    18.         this.Y = y;
    19.         this.Width = width;
    20.         this.Height = height;
    21.     }
    22.  
    23.  
    24.     public AnimationCurveRangeAttribute(int width, int height)
    25.     {
    26.         this.X = 0;
    27.         this.Y = 0;
    28.         this.Width = width;
    29.         this.Height = height;
    30.     }
    31. }
    32.  
    33. [OdinDrawer]
    34. public sealed class AnimationCurveAttributeDrawer : OdinAttributeDrawer<AnimationCurveRangeAttribute, AnimationCurve>
    35. {
    36.     protected override void DrawPropertyLayout(IPropertyValueEntry<AnimationCurve> entry, AnimationCurveRangeAttribute attribute, GUIContent label)
    37.     {
    38.         Rect ranges = new Rect(attribute.X, attribute.Y, attribute.Width, attribute.Height);
    39.  
    40.         if (label == null) // Labels are optional in Odin.
    41.             entry.SmartValue = EditorGUILayout.CurveField(label, entry.SmartValue, Color.white, ranges);
    42.         else
    43.             entry.SmartValue = EditorGUILayout.CurveField(entry.SmartValue, Color.white, ranges);
    44.     }
    45. }
    I would love to see any modifications you might make to it, if you decide to use it.
     
    Michael_Berna likes this.
  33. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Hi, I'm using Odin to create scriptable objects that contain dictionary's for lookup of prefabs. Before Odin I had been using a custom editor to set or change prefab entries in an array and then at runtime building the dictionary with the array data. Now I would like to use Odin to serialize the data into the dictionary.

    I'm trying to accomplish this but I think I need a way to force Odin to serialize the dictionary. Previously in my editor when a change was made to the array I would call EditoryUtility.SetDirty( myScriptableObject ).

    Is there an API call to force Odin to serialize?
     
  34. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    You need to remember to derive from SerializedScriptableObject in order for Odin to be able to serialize your dictionary. Just having a regular ScriptableObject and using [ShowInInspector], as you may have, is definitely not enough. That will merely cause it to be shown, not serialized, and there is a big difference between the two.

    This is the only code you need to get a modifiable, serialized dictionary in your ScriptableObject inspector:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using Sirenix.OdinInspector;
    4.  
    5. [CreateAssetMenu(fileName = "My Scriptable Object")]
    6. public class MyScriptableObject : SerializedScriptableObject
    7. {
    8.     public Dictionary<string, GameObject> prefabLookup = new Dictionary<string, GameObject>();
    9. }
    Of course, Odin will automatically mark your asset dirty when it needs to be - you don't need to worry about that.
     
  35. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Hmm I've done that so I must have a problem somewhere else.

    I am using a Tuple for the key though I don't think that would matter?

    I should maybe also mention that I'm still using my custom editor to edit the scriptable object.


    Code (CSharp):
    1. var prefab = EditorGUILayout.ObjectField( gameobject )
    2. if( EditorGUI.EndChangeCheck() )
    3. {
    4.      var key = Tuple.Create( item1, item2 );
    5.      if( PrefabMap.PrefabDictionary.ContainsKey( key ) )
    6.           PrefabMap.PrefabDictionary[key] = prefab;
    7.      else
    8.           PrefabMap.PrefabDictionary.Add( key, prefab );
    9. }
     
    Last edited: Sep 29, 2017
  36. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    Hmmm. Yes, that would be it. We don't currently have explicit support for tuple serialization, and it seems they're a little funky and don't work by default. I will add a special case for tuples, quickly. Please send me a mail at tor@sirenix.net with your Odin invoice ID, and I'll send you a build with a hotfix for this.
     
    tgaldi likes this.
  37. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Thanks for the assistance!

    For anyone interested, I'm not using the .Net Tuple implementation but rather:
    https://gist.github.com/michaelbartnett/5652076

    Because of this Tor advised me to simply add [SerializeField] to any private fields and add parameter-less constructors.
     
    Last edited: Sep 29, 2017
    Tor-Vestergaard likes this.
  38. Gamrek

    Gamrek

    Joined:
    Sep 28, 2010
    Posts:
    164
    Hello,

    I love your asset, but I have a question.

    I have a scriptableobject which store game data to use in level as well as having a button to create element for the game (only in editor to speed up level design process). Before I use something called "ClassTypeReference" from here.

    But after I imported your asset, that doesn't work anymore. And this is how I do this now.

    Code (CSharp):
    1. public class ABC : MonoBehaviour
    2. {
    3.     public string HelloWorld;
    4. }
    5.  
    6. public class HelloScriptableObject : SerializedScriptableObject
    7. {
    8.     public System.Type component;
    9.     [Button("Make Something")]
    10.     public void Make()
    11.     {
    12.         GameObject newHelloWorld = new GameObject();
    13.         newHelloWorld.AddComponent(component);
    14.         newHelloWorld.HelloWorld = "Hello World";
    15.     }
    16. }
    I just want to know if this is the only way to do it with Odin. The thing is with this, I need to enable Odin's serialization. And I am not sure if I want to do this. Can you suggest some other way to do this without Odin's serialization?

    thanks

    Derek
     
  39. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    Hi - that asset you linked should just work straight out of the box as far as I can tell, so the fact that it doesn't must be a bug with how we detect legacy Unity property drawers. I will take a look at what exactly is going on here.

    Meanwhile, you should be able to just use everything the way you did before Odin, if you merely apply the [DrawWithUnity] attribute onto your ClassTypeReference fields, which will force Odin to call into Unity's old property drawer system to draw that particular field. A little tedious, but it should work fine as a temporary fix until I've tracked the bug down. I'm heading to Unite Austin very soon, so that might be a little while.
     
    DonLoquacious likes this.
  40. Gamrek

    Gamrek

    Joined:
    Sep 28, 2010
    Posts:
    164
    This works! thank you so much for your response!
     
  41. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I thought there would be something like this already available in Odin but it's not the case:

    - Adding the tags of Unity to the inspector.

    I took the code from this website (http://www.brechtos.com/tagselectorattribute/ ) so that I can get the tags exposed to the inspector but I get errors due to OdinInspector.

    Code (CSharp):
    1. "
    2. ArgumentException: An element with the same key already exists in the dictionary.
    3. System.Collections.Generic.Dictionary`2[System.Type,Sirenix.OdinInspector.Editor.DrawerPriority].Add (System.Type key, DrawerPriority value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
    4. Sirenix.OdinInspector.Editor.DrawerLocator..cctor () (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/GroupPropertyChildren.cs:30)
    5. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Sirenix.OdinInspector.Editor.DrawerLocator
    6. System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (RuntimeTypeHandle type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.CompilerServices/RuntimeHelpers.cs:101)
    7. UnityEditor.EditorAssemblies.ProcessEditorInitializeOnLoad (System.Type type) (at C:/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:136)
    8. UnityEngine.Debug:LogException(Exception)
    9. Sirenix.OdinInspector.Editor.InspectorUtilities:DrawPropertiesInTree(PropertyTree) (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Infos/InspectorPropertyInfo.cs:521)
    10. Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Utilities/Persistent/PersistentContextCache.cs:416)
    11. Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Misc/DrawerPriorityAttribute.cs:44)
    12. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    13. "
    Does someone know what the reason is?
     
    Last edited: Oct 7, 2017
  42. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    If you're talking about turning a string field into a tag selector dropdown, that was one of the first things I needed for Odin as well. Here's the one I made:

    TagSelectorAttribute.cs
    Code (CSharp):
    1. namespace Sirenix.OdinInspector
    2. {
    3.     using System;
    4.  
    5.     [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    6.     public class TagSelectorAttribute : Attribute
    7.     {
    8.     }
    9. }
    And in an Editor folder,
    TagSelectorAttributeDrawer.cs
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. namespace Sirenix.OdinInspector.Editor.Drawers
    3. {
    4.     using Utilities.Editor;
    5.     using UnityEngine;
    6.     using UnityEditor;
    7.     using System.Linq;
    8.     using System.Collections.Generic;
    9.  
    10.     [OdinDrawer]
    11.     public class TagSelectorAttributeDrawer : OdinAttributeDrawer<TagSelectorAttribute, string> // Draw for tag field attributes on string members
    12.     {
    13.         protected override void DrawPropertyLayout(IPropertyValueEntry<string> entry, TagSelectorAttribute attribute, GUIContent label)
    14.         {
    15.             entry.SmartValue = label != null ? EditorGUILayout.TagField(label, entry.SmartValue)
    16.                                              : EditorGUILayout.TagField(entry.SmartValue);
    17.         }
    18.     }
    19. }
    20. #endif
    It uses Unity's own TagField so it's a lot less fragile. Like I said, it was one of the first "testbed" attributes I hacked together when I started switching over to Odin, so there may be newer API changes that can handle some stuff better, but it still works. You're welcome to use it.

    You can use it like this:
    Code (CSharp):
    1. [TagSelector]
    2. public string SomeTagField;
    Hopefully that helps!
     
  43. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Thanks for helping out electroflame, there's the one issue that I can't put several tags in there, the code on the website here (http://www.brechtos.com/tagselectorattribute/ ) allows that.

    This can be useful for many situations; I personally want to use it for hitboxes that can hit more than one tag.
     
  44. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    You should be able to use it on a List<string> (or a string[]).

    Code (CSharp):
    1. [TagSelector]
    2. public List<string> ValidHitBoxTags = new List<string>();
    I can't test that right now, but it should let you populate a list with as many tag dropdowns as you need. There isn't any (easy) way to store more than one tag in a string field, so you have to store them as a List or Array and iterate over that. The TagSelector Odin Drawer should work on collections.
     
    Tor-Vestergaard and FeastSC2 like this.
  45. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    That's true, it works! Thanks electroflame.
     
  46. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    You're welcome! Glad you got what you needed out of it!
     
    Tor-Vestergaard and FeastSC2 like this.
  47. Tim0n

    Tim0n

    Joined:
    Mar 11, 2015
    Posts:
    3
    Hey, I can't seem to get arrays to work when they're declared in a struct.

    I have this super simple struct and all I want to do is set some default values in a ScriptableObject.
    Code (CSharp):
    1. public struct RandomStruct
    2. {
    3.     [ShowInInspector]
    4.     public string RandomString { get; private set; }
    5.     [ShowInInspector]
    6.     public byte[] RandomArray;
    7. }
    But when I look at it in the inspector the string works fine butI can't seem to set any values to the array. It works fine if I just keep an array straight in the ScriptableObject but once I move it to a struct it dosen't work anymore. Am I missing something crucial here or is this non-working at the moment?




    This is how it looks in the inspector
     
  48. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    188
    That looks like a bug we currently have a fix for in the upcoming patch 1.0.5.2, which is chock full of fixes and tweaks. If you send me your Odin invoice number at tor@sirenix.net, I'll send you our release candidate build right away.
     
    Tim0n likes this.
  49. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    Could you add an excludeParentDirectoryName parameter to the FilePath Attribute?
    Code (CSharp):
    1. [EnableIf("active"), LabelText("Files to build"), FilePath(ParentFolder = "$WatchKitAppDir")]
    2. public string[] WatchKitAppFilesToBuild;
    this way you could simply combine $parentFolder with the the relative file path.
     
    Last edited: Oct 19, 2017
  50. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    13
    Hey, how can I get serialzied UnityEvent fields on ScriptableObjects do display normally? I've tried adding [DrawWithUnity] to the field, and turning off the Odin for my custom asset type, but neither does the trick.

    The other project that I've been using these in was still in 5.6, is this something Unity killed on their end in 2017.x?