diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/CopyAndPasteProperty.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/CopyAndPasteProperty.cs index 1911fae..9b6c8b8 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/CopyAndPasteProperty.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/CopyAndPasteProperty.cs @@ -1,4 +1,5 @@ -#if UNITY_2019_3_OR_NEWER +// NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later. +#if UNITY_2021_3_OR_NEWER using UnityEditor; using UnityEngine; diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs index 5cc7223..6f96e4c 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs @@ -8,14 +8,19 @@ namespace MackySoft.SerializeReferenceExtensions.Editor { public static class ManagedReferenceUtility { public static object SetManagedReference (this SerializedProperty property,Type type) { - object result; + object result = null; + +#if UNITY_2021_3_OR_NEWER + // NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later. if (property.managedReferenceValue != null) { // Restore an previous values from json. string json = JsonUtility.ToJson(property.managedReferenceValue); result = JsonUtility.FromJson(json, type); } - else +#endif + + if (result == null) { result = (type != null) ? Activator.CreateInstance(type) : null; }