Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug rendering for SerializedObject and SerializedProperty #1991

Merged
merged 12 commits into from
Jan 12, 2021

Conversation

citizenmatt
Copy link
Member

This PR adds debugging extensions for SerializedObject and SerializedProperty:

  • Add a Serialised Properties node to SerializedObject to show the root property instance and allow viewing the hierarchy of properties
  • Add a value presenter to provide a "compact" presentation of the SerializedProperty, showing name, property type and the correct value.
  • Filter out invalid properties from SerializedProperty so the correct accessors are shown for the current property type, e.g. intValue is shown for SerializedPropertyType.Integer, stringValue for strings, and so on. Private or irrelevant properties are filtered out.
  • Add a Raw View group to SerializedProperty to show all fields and properties, without filtering.
  • Additional data is shown for character and enum properties, which are represented by integers. Character values show the actual character, and the enum index is converted into an enum name.
  • Add a Children node to SerializedProperty to show child properties, allowing access to the full hierarchy of serialised data.
  • Add an array group node to SerializedProperty to show the contents of an array or fixed buffer. The array results will be chunked for large arrays, as per options.

All values are calculated lazily, and the Unity debugger extension can already be disabled in the settings.

As viewed in the debugger:

Screenshot 2021-01-05 at 2 11 06 pm

For more background, SerializedObject and SerializedProperty are the main APIs for working with Unity's serialised data - assets, scenes, prefabs and so on. Unity serialises data not just to save to disk but also to work with domain reloading, and especially editor interaction - editor windows work with serialised data rather than raw C# objects to allow for things such as change tracking and undo.

The SerializedObject type is the root of the stream of serialised data and represents a handle on the root serialised object - asset, scene, prefab, etc. It allows for retrieving the root SerializedProperty, as well as access to the target C# object.

The SerializedProperty type is a view on the stream of serialised data. It can be considered a cursor, and will be updated in-place as the data is iterated. The serialised data is hierarchical, representing a tree of properties, where a property can be a scalar value or an array, or a serializable C# class with child properties for serialised fields. However, the data is serialised as a linear stream. Iterating the stream will walk the hierarchy in a depth first fashion. Calling SerializedProperty.Next(true) will step into a child before stepping out and on to the next sibling (Next(false) will skip the children and move directly to the next sibling).

SerializedProperty is a discriminated union, with an enum indicating the type, and strongly typed accessor properties to retrieve the data, e.g. intValue, stringValue, vector2Value, etc.

@citizenmatt citizenmatt added this to the Rider 2021.1 milestone Jan 5, 2021
@citizenmatt citizenmatt self-assigned this Jan 5, 2021
@krasnotsvetov krasnotsvetov self-requested a review January 12, 2021 13:14
@citizenmatt citizenmatt merged commit 735f00f into net211 Jan 12, 2021
@citizenmatt citizenmatt deleted the net211-mte-debug-serialised-property branch January 12, 2021 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants