Skip to content

Instantly share code, notes, and snippets.

@Quickz
Created May 8, 2021 22:48
Show Gist options
  • Save Quickz/4b961ab9546b39c0f6fb5a9b2ccb646a to your computer and use it in GitHub Desktop.
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.
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