Search Unity

Productivity tips with Odin: A tool for making tools

September 16, 2021 in Games | 5 min. read

Odin, a Unity Verified Solutions Partner (VSP) offers a suite of products to improve productivity for your next project. With over 100 attributes to streamline workflow, Odin Inspector lets you enjoy the benefits of a powerful, customized, and user-friendly editor without writing any custom editor code. Meanwhile, the powerful and extensible Odin Serializer, alongside the Odin Validator, which scans your work for underlying issues, similarly serve to support your most ambitious endeavors. 

Want to make the most of Odin? Let’s take a look at five tips that can help save you time, maximize efficiency, and enhance your overall processes.

Menu 6

Clean up cluttered inspectors with group attributes

Large scripts with many inspector variables can be difficult to keep track of – not to mention, visually unappealing. Groups in Odin exist to address this problem. By giving you the capacity to combine related properties and draw them in a variety of ways (think labeled boxes, drop-downs, and multipage tabs), groups keep your inspector neat and manageable.

But how do groups actually work? Through the association of attributes with the same name, you can combine them with relevant members. Check out the GIF below, as we enable and disable Odin to show some of the possible effects of group attributes:

Menu 5

Write C# expressions directly within attributes

Many attributes let you include string parameters that conveniently reference members or contain C# expressions to be evaluated. This allows you to quickly inject basic logic into your inspector.

Attribute expressions, denoted by a string that starts with an ‘@’ symbol, are extremely flexible. They equip you to add custom logic and behavior to any of Odin's attributes, without the necessity of creating countless extra members. See just how simple the expressions are in the below example:

C# expressions

Use validation attributes to avoid introducing bugs

Mistakes often occur when individuals don’t know how a certain component works, which can lead them to accidentally set an invalid value, or neglect to assign an essential value altogether. In many cases, developers will try to solve this issue by manually writing a custom, user-friendly editor for configuration.

With many attributes to support developers in their aims, Odin is prepared to deliver. The following GIF demonstrates a few common attributes such as ChildGameObjectsOnly, ValidateInput, and Required:

Validation attributes to avoid introducing bugs

You can even introduce custom global validation rules to your project that Odin Inspector will pick up.

What really brings all of these features together is the Odin Validator add-on. This add-on prompts you to scan your project and provides warnings for any outstanding errors. So, let’s say you introduced a new (unexpectedly erroneous) requirement to an asset in thousands of places within your project; Odin Validator will help you detect, flag, and rectify this issue.

Build custom Unity Editor Windows using attributes

Please note that there are two types of Odin classes to inherit from: OdinEditorWindow and OdinMenuEditorWindow. In this section, we focus on OdinEditorWindow. 

Whether you’d like to access an overview of your project, handle large sets of data, or create custom tools, editor windows go a long way to ease and streamline your project’s production workflow.

More specifically, OdinEditorWindow allows you to inherit from a single class and access the Odin drawing system in its entirety. By inheriting from OdinEditorWindow rather than EditorWindow, you can effectively render fields, properties, and methods without writing any custom Editor GUI code. The below GIF shows just how straightforward this process can be:

Menu 3

Inherit from SerializedScriptableObject to serialize polymorphic data structures

It’s no secret that Unity prioritizes simple and efficient serialization. However, there are unique cases where making use of more complex data structures and features, such as dictionaries, inheritance, and delegates, is recommended – or even required. 

Odin Serializer brings out-of-the-box support for saving and rendering to the inspector, so you can take on these intricate elements. In fact, you can utilize recent subsets of polymorphic (inheritance) serialization capabilities within the inspector thanks to [SerializeReference]. The following example highlights just some of the serialization and inspector capabilities:

Menu 1

Odin has the right tools to help increase your productivity and improve workflow for just about any project. We hope that you’ll find these suggestions helpful in your own endeavors and stay tuned for exciting new features, including a major Validator update coming later this year.

To get started with Odin, download a personal license from the Unity Asset Store. If your project requires an enterprise solution, you can learn more here. For additional tips, check out the Odin YouTube channel.

September 16, 2021 in Games | 5 min. read
Related Posts