Previews

Exciting new features that we hope you'll help us get right!
 

Odin UI Toolkit Integration Preview


Odin Inspector can now render Visual Elements (UI Toolkit) in ImGUI! We're inviting you to test this early Alpha Preview version and share your feedback.

Keep in mind that the current minimum Unity version for this preview build to run at all is Unity 2020.3, though there is a small chance it may work in 2020.2 (we have not tested this). It should also support the latest 2023.x Unity beta and alpha versions just fine. Later preview versions should support down to the current base requirement of Unity 2019.4, though the UI Toolkit integration will not function on any version lower than 2020.2 (estimated).

This new feature is made possible by our OdinImGuiElement integration, allowing you to draw visual elements inside ImGUI from anywhere, even in non-Odin editors. You can also utilize this API manually in your own ImGUI code to embed arbitrary visual elements anywhere:

using Sirenix.OdinInspector.Editor.Internal.UIToolkitIntegration;

// Your element goes in the constructor.
// You can also give it a serializedProperty.
private OdinImGuiElement SomeElement = new OdinImGuiElement(new ListView());

private void OnGUI()
{
    GUILayout.BeginVertical();
    var rect = ImguiElementUtils.EmbedVisualElementAndDrawItHere(this.SomeElement);
    // Or optionally with a label:
    //var rect = ImguiElementUtils.EmbedVisualElementAndDrawItHere(this.SomeElement, new GUIContent("Custom label"));
    GUILayout.EndVertical();
}

In addition to the manual API above, Odin will now draw any Unity PropertyDrawer, DecoratorDrawer and inlined Editor as an embedded VisualElement if it provides one, with a fallback to normal ImGUI. You can also force a property to be drawn with visual elements by applying the new DrawWithVisualElements attribute to it.

Keep in mind that it's an alpha preview; there will probably be some edge case stability issues, and we'll probably change the API and namespaces around a bit before any official release.

Please report issues or give any other feedback in the Discussion/Feedback thread linked below. These are the currently known issues:

  1. Inconsistent tab key navigation between ImGUI and Visual Elements controls.
  2. Unity DecoratorDrawers can render twice in some cases.
  3. Dragging and dropping in an Odin ImGUI rendered list can be frustrating due to pauses when hovering over visual elements, as ImGUI stops receiving events until the mouse leaves the element.
  4. Drag and drop on IMGUI lists containing rendered IMGUI elements can break entirely in rare edge cases. We've only found one case where it does so, specifically for the FilePath attribute example in the attribute overview, if the strings in the array are forced to be drawn with visual elements. It failed to reproduce in other inspectors or windows, so we are not yet certain what the problem is here.
  5. Label widths in visual elements are often wrong or inconsistent with standard IMGUI label widths.

Thank you for your support and input as we work on this feature!

Download | Discussion & Feedback

Units and Smart Fields Preview


Introducing enhanced number interaction with Unit and smart fields in Odin Inspector.

The new Unit attribute allows you to define a field's value, such as meters, and easily switch units without changing the underlying code. You can even input values in other units, and the inspector will automatically convert them. With over 200 built-in units, Unit and Smart Fields offer a more flexible way of handling numerical values.

The Unit system also comes with a new Unit Overview window, allowing overview of all units in your system, including custom units you've added. It's accessible from the Odin menu, or by right clicking a unit field in the inspector.

Smart fields enable scripting directly into a field's text box using Odin expressions by starting with an @ character. They also maintain a history of your entries for quick navigation.

How to use

// A meters field. The user can enter other values and convert them to meters, or change the display on the fly.
[Unit(Units.Meter)]
public float Meters;

// Radians field shown in degrees. The user can still enter other values and change the display as they want.
[Unit(Units.Radian, Units.Degree)]
public float RadiansDisplayedAsDegrees;

// You can reference units by name. Useful for using custom units.
[Unit("Meters per Second")]
public float MetersPerSecond;

// Combine with ShowInInspector and properties can be used as a kind of debug field by displaying a value in multiple units at once.
// ForceDisplayUnit prevents users from change the unit in the inspector, and DisplayAsString, well, displays as string.
[ShowInInspector, Unit(Units.MetersPerSecond, Units.KilometersPerHour, ForceDisplayUnit = true, DisplayAsString = true)]
public float KilometersPerHour => MetersPerSecond;

Fairly simple, but it can be surprisingly hard to wrap your head around. Just remember: The actual unit never changes. A meters field will always be a meters field, regards of whether it's displayed as nanometers or light-years in the inspector.

API

As always, you can utilize our API to implement custom behaviors yourself.

All the new unit and smart field behaviors can be found in the SirenixEditorFields (Sirenix.Utilities.Editor) class, alongside all other custom Odin fields. The new methods are UnitField, SmartUnitField, and SmartField, with variations for different primitive data types.

In UnitNumberUtility (Sirenix.Utilities.Editor), is the core of the new unit system. The class contains definitions for all implemented units and conversion methods. You can also use the AddCustomUnit methods to add custom units, and they will work with the unit fields.

The UnitInfo (Sirenix.Utilities.Editor) class defines a unit in the Unit system. It contains a unit's name, symbols, category, and conversion instructions.

Limitations

Unit and Smart Fields are currently available only as standalone number fields, and other attributes like Range or Delayed have not yet been implemented to work with them. The size of the field you use with units will affect precision, as conversion logic is implemented as decimal numbers. And before anyone asks, no, this will not work at runtime! If you want to convert units at runtime, though, you can easily go grab the conversion ratios you need from the Unit Overview and convert the values manually in your code.

We welcome feedback on the Unit system, built-in units, and any issues related to interacting with Unit and smart fields, as well as suggestions for improvements.

Download | Discussion & Feedback