Created
May 8, 2021 22:48
-
-
Save Quickz/4b961ab9546b39c0f6fb5a9b2ccb646a to your computer and use it in GitHub Desktop.
[Unity] Gets the target value of a property. In other words, if you have a serialized class and you want to get it's instance from the property, use this method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
public static class SerializedObjectUtility | |
{ | |
public static object GetTargetValue(this SerializedProperty property) | |
{ | |
var targetObject = property.serializedObject.targetObject; | |
var field = targetObject.GetType().GetField(property.propertyPath); | |
return field?.GetValue(targetObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment