Skip to content

Instantly share code, notes, and snippets.

@Quickz
Quickz / SerializedObjectUtility.cs
Created May 8, 2021 22:48
[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);