Provides complete control over SerializeReference fields with smart type management and validation. Features include customizable type hierarchies, inheritance-based filtering, object instantiation callbacks, and display name customization through intuitive attributes. Streamlines serialized polymorphic data editing in the Unity inspector.
Unity Project
Built with Unity 2022.3.62f2 · download the source from GitHub
README
Rendered from GitHubSerialize Reference Editor for Unity
A powerful Unity editor extension that provides complete control over SerializeReference fields with smart type management, validation tools, and data integrity features.
Installation
Download asset from Unity Asset Store: Serialize Reference Editor
Please, remove old version Serialize Reference Editor for Unity before update!
Or installation as a unity module via a git link in PackageManager:
https://github.com/elmortem/serializereferenceeditor.git?path=SerializeReferenceEditor/Assets/SREditor/Package
Or direct editing of Packages/manifest is supported.json:
"com.elmortem.serializereferenceeditor": "https://github.com/elmortem/serializereferenceeditor.git?path=SerializeReferenceEditor/Assets/SREditor/Package",
Main types
SR attribute
Use it to mark the fields that you want to edit. Important note - they should also be marked with the SerializeReference attribute. You can mark the base type (including the interface) with it. Allows you to change an array, a list, and a single element. Displays the current field type.
Example:
[SerializeReference, SR]
public List<AbstractData> DataList = new List<AbstractData>();
Result:
Additional features
You can override SRAttribute and implement a rule for processing instantiated objects.
You can see an example in SRDemoAttribute.cs, where the OnCreate method was overriden:
public override void OnCreate(object instance)
{
if(instance is AbstractData)
{
((AbstractData)instance).DataName = instance.GetType().Name;
}
}
SRName attribute
Mark classes with them if you want to customize the display name and nesting hierarchy in the search tree for a specific type.
Example FloatData.cs:
[SRName("Data/Simple types/Float")]
public class FloatData : AbstractData
{
[Range(0f, 1f)]
public float Float;
}
You can modify the display settings for the class name without specifying an attribute by navigating to Edit -> Project Settings -> SREditor.
SRHidden attribute
Mark classes with this attribute to hide them from the type selection menu. Types with this attribute will not appear in the search tree.
SRDrawer
SRDrawerOptions
Provides configuration options for the SRDrawer:
WithChild- Controls whether child properties should be displayedButtonTitle- Controls whether the type name should be displayed on the buttonDisableExpand- Disables the property expansion functionality
SRDrawer.Draw
SRDrawer.Draw is a key method for rendering fields with the SerializeReference attribute. It provides the following functionality:
Key Features
- Dynamic type resolution for the field
- Type selection button displaying current type name
- Array elements support
- Integration with Unity's SearchWindow for type selection
Method Parameters
position: Drawing area position and dimensionsproperty: Serialized property to drawlabel: Field label to displaytypes: Optional array of allowed types
Example CustomDataDrawer.cs
[CustomPropertyDrawer(typeof(CustomData))]
public class CustomDataDrawer : PropertyDrawer
{
private SRDrawer _drawer = new();
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var dataProperty = property.FindPropertyRelative("Data");
_drawer.Draw(position, dataProperty, label);
}
}
SRDrawer.GetButtonWidth
SRDrawer.GetButtonWidth method allows to get the width of the type selection button. Useful for custom property drawers when you need to adjust layout based on the button size.
Method Parameters
property: Serialized property to calculate button width foroptions: SRDrawerOptions to use for calculation
Tools
Missing Types Validator
You can use the built-in tool to search for lost types.
(this error occurs if the serialized data stores information about a type that no longer exists and could have been deleted during development). To start, you can run
Tools -> SREditor -> Check MissingTypes
At least one
SRMissingTypesValidatorConfigis required to work. If necessary, you can implement your ownIAssetMissingTypeReportfor error reporting if you use it in CI/CD systems. You can also implement your ownIAssetsLoaderif the defaultLoadAllScriptableObjectsis not suitable for you.
Class Replacer
Use Tools -> SREditor -> Class Replacer for replace Serialize Reference classes.
FormerlySerializedType attribute
It is analogue of attribute FormerlySerializedAs, but works for Serialize Reference classes.
Example NewTestData.cs:
[Serializable, SRName("New Test")]
[FormerlySerializedType("SRDemo, Demo.OldTestData")]
public class NewTestData : BaseTestData
Duplicate Cleaner
Now Serialize Reference Editor can auto detect and handle SerializeReference object duplicates with flexible settings - you can nullify them, create them with default values, or make deep copies, preventing issues with unwanted reference sharing in your assets.
Thanks
Support Unity 2021.3 or later.
Use for free.
Enjoy!
Versions 14
- v1.3.0 —
- v1.3.14 —
- v1.3.13 —
- v1.3.12 —
- v1.3.11 —
- v1.3.10 —
- v1.3.9 —
- v1.3.8 —
- v1.3.7 —
- v1.3.6 —
- v1.3.5 —
- v1.3.3 —
- v1.3.2 —
- v1.3.1 —
Dependencies 0
No dependencies.
Changelog 14 releases
- v1.3.0
New Features: 1. Class Replacer - Added new tool for replacing Serialize Reference classes - Access via Tools -> SREditor -> Class Replacer 2. FormerlySerializedType attribute - Added new attribute for handling class renaming/refactoring - Works similar to FormerlySerializedAs but for Serialize Reference classes 3. Duplicate Cleaner - Added new system for handling SerializeReference object duplicates - Configurable settings: nullify, create with default values, or make deep copies - Prevents issues with unwanted reference sharing in assets 4. SRDrawer improvements - Added comprehensive Draw method with support for: - Dynamic type resolution - Type selection button - Array elements support - SearchWindow integration
- v1.3.14
- Change CreateAssetMenu path for SRMissingTypesValidatorConfig - Update changelog
- v1.3.13
- Bugfix - Update IDE packages
- v1.3.12
- Add SerializeReference field with SR attribute correct error
- v1.3.11
- TypeInfoComparer fix
- v1.3.10
- SRHidden fix
- v1.3.9
- Fix error with editor namespace on build (thanks @Red-Cat-Fat)
- v1.3.8
- DropdownButton fix
- v1.3.7
- SRDrawer.GetButtonWidth added
- v1.3.6
- Type upgrader fix - Duplicate cleaner fix
- v1.3.5
- Reselection fix
- v1.3.3
- Fix namespace and assembly replace
- v1.3.2
- Added SRHidden attribute, for hide type at select list - Update Demo files
- v1.3.1
- Added SRDrawerOptions to Draw method
Comments
No comments yet. Be the first!

Sign in to join the conversation
Sign In