Design with Attributes

A core feature of Odin is how easy it makes it to change the appearance of your scripts in the editor - essentially letting you create powerful, complex custom editors at a whim merely by applying a few attributes to your members.

We strongly recommend that, after installing Odin, you take a look at our "1 - Odin Attributes Overview" demo scene found under Plugins/Sirenix/Demos/Odin Inspector, which contain example demonstrations for almost all of the attributes that Odin makes available. The scene will let you see what the attributes do directly in the inspector, and the examples contain various informative notes as to the use of each attribute. Studying this scene is the best way to get a basic overview of everything that you can do with Odin's default attributes.

Using Attributes

You can think of an attribute as an adjective that describes extra qualities you want your values to have. You may already be familiar with the concept; a basic version of it exists in Unity already, and Unity provides a few attributes that you can use to customize the appearance of your inspector to a limited degree.

Unity's own RangeAttribute, for example, lets you constrain a number value to be within a range, and provides a handy graphical slider to adjust the value within that range.

Of course Odin supports all of Unity's attributes, and adds many more of its own. Simply add "using Sirenix.OdinInspector" to the top of your csharp script, and you'll instantly be able to leverage the power of all Odin's attributes. Our ValueDropdown attribute, for example, lets you easily provide a list of value options for any kind of value.

In vanilla Unity, however, most of these attributes merely change how a single value is drawn. Many of Odin's attributes are far broader in scope. The following sections give a brief overview over what kinds of attributes exist, and what you can do with them. Please see the attribute documentation to get a list of all inspector attributes that exist in Odin.

Ordering

You can easily change the order in which things are displayed, by applying a PropertyOrderAttribute, which takes a simple order number. Members are ordered first by their order number (which is 0 by default), and then by the order in which they are written in the script itself, though different member types will always be displayed separately (see below paragraph). Priorities are sorted in ascending order, meaning lower numbers are displayed first.

As implied above, with Odin, you can show all kinds of things in the inspector; not just fields, but also properties and methods. Usually such members would be displayed separately, but with property ordering you can easily interweave members of all kinds with each other.

Grouping

Have you ever had a very large script with many inspector variables, and found it a little difficult or tedious to keep track of them all in the inspector? Groups in Odin exist to address this problem, and help greatly with keeping your inspector manageable and nice to look at.

What they do lies in the name: groups let you group together related properties, and draw them in any variety of ways, from simple labeled boxes and dropdowns to multi-page tab groups. Using them is easy; simply put group attributes with the same name on the members you want to group together.

Groups also support ordering; set the order of any single group attribute by passing it along as a second parameter.

Applying PropertyOrderAttribute to individual properties in a group adjust their ordering within the group.

Odin also makes it trivial to add your own group types to the inspector, see the page Creating a new group drawer for an in-depth guide.

Meta Attributes

Some attributes don't do anything as tangible as changing how, where or when a value is drawn. Instead, they're more reactive in nature, and add some basic intelligence to the inspector. They allow you to perform more complicated tasks like validating input, invoking a method when a value is changed, and many other such things.

Using such meta attributes, any programmer has a powerful, easy-to-use suite of tools available to help enforce necessary rules, as well as assist, constrain and guide the designers that use the inspector by providing feedback, relevant information and tooltips at the right times, resulting in an overall smoother workflow, less prone to errors and mistakes.

Validate Your Scene

As seen in the above section, Odin offers powerful facilities for specifying rules that the data on your components have to obey, mostly through the [ValidateInput] attribute.

Violations of these rules will be clearly indicated in the inspector while the object in question is selected; however, this is often not enough, as opening the inspector on various objects to check whether rules are obeyed can quickly get very tedious, and it can be easy to miss violations. Therefore, Odin also lets you easily verify that all validation rules are obeyed in a given scene, using the Scene Validator, which can be found under Tools -> Odin Inspector -> Scene Validator.

The Scene Validator will inspect all GameObjects in the scene, and give you a list of all GameObjects sorted by the kinds of violations that are present in them. Violations are determined by whether they trigger warning or error message boxes to appear. You can inspect the relevant objects directly in the window, and fix the violations right there.