Skip to content

Commit f7ed2d0

Browse files
committed
Update documentation
1 parent bb6b44d commit f7ed2d0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Assets/Editor Toolbox/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,20 @@ public int var1;
631631
#### SerializeReference (ReferencePicker) <a name="toolboxreference"></a>
632632

633633
You can draw properties marked with the **[SerializeReference]** attribute with an additional type picker that allows you to manipulate what managed type will be serialized.
634-
634+
Depending on the picked type we have different object creation strategies:
635+
- `Activator.CreateInstance(targetType)` (default constructor will be called and all readonly members will be initialized)
636+
- Target type has default constructor
637+
- Target type is a value type
638+
- `FormatterServices.GetUninitializedObject(targetType)` (object will be uninitialized)
639+
- Target type has one or more constructors with arguments
640+
- `ForceUninitializedInstance` property is set to true
641+
635642
To prevent issues after renaming types use `UnityEngine.Scripting.APIUpdating.MovedFromAttribute`.
636643

637644
```csharp
638645
[SerializeReference, ReferencePicker(TypeGrouping = TypeGrouping.ByFlatName)]
639646
public Interface1 var1;
640-
[SerializeReference, ReferencePicker]
647+
[SerializeReference, ReferencePicker(ForceUninitializedInstance = true)]
641648
public Interface1 var1;
642649
[SerializeReference, ReferencePicker(ParentType = typeof(ClassWithInterface2)]
643650
public ClassWithInterfaceBase var2;

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,20 @@ public int var1;
631631
#### SerializeReference (ReferencePicker) <a name="toolboxreference"></a>
632632

633633
You can draw properties marked with the **[SerializeReference]** attribute with an additional type picker that allows you to manipulate what managed type will be serialized.
634-
634+
Depending on the picked type we have different object creation strategies:
635+
- `Activator.CreateInstance(targetType)` (default constructor will be called and all readonly members will be initialized)
636+
- Target type has default constructor
637+
- Target type is a value type
638+
- `FormatterServices.GetUninitializedObject(targetType)` (object will be uninitialized)
639+
- Target type has one or more constructors with arguments
640+
- `ForceUninitializedInstance` property is set to true
641+
635642
To prevent issues after renaming types use `UnityEngine.Scripting.APIUpdating.MovedFromAttribute`.
636643

637644
```csharp
638645
[SerializeReference, ReferencePicker(TypeGrouping = TypeGrouping.ByFlatName)]
639646
public Interface1 var1;
640-
[SerializeReference, ReferencePicker]
647+
[SerializeReference, ReferencePicker(ForceUninitializedInstance = true)]
641648
public Interface1 var1;
642649
[SerializeReference, ReferencePicker(ParentType = typeof(ClassWithInterface2)]
643650
public ClassWithInterfaceBase var2;

0 commit comments

Comments
 (0)