I’m working on an editor script which isn’t an inspector one. I have some field names as a string and I need to change their value. I really don’t want to use Reflection for a number of reasons and so I’m looking into SerializedObject.
I know that a SerializedProperty can be modified easily via EditorGUI.PropertyField but is it possible to modify a SerializedProperty’s value fields and have that change applied to the serialized object?
This is what I have:
SerializedObject serialized = new SerializedObject(mod.target);
serialized.Update();
SerializedProperty property = serialized.FindProperty(propertyPath);
if (property != null)
{
property.floatValue = float.Parse(value);
serialized.ApplyModifiedProperties();
}
Unfortunately this doesn’t change the value - in this case I’m trying to modify the mass of a Rigidbody component. mod.target holds the Rigidbody reference and propertyPath contains “m_Mass” (yes, not “mass” but “mass” also doesn’t work)
Any ideas on how to make this work? I really, really, really don’t want to use Reflection ![]()