Modifying a SerializedProperty object outside editor API [SOLVED]

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 :slight_smile:

It turned out that the problem was caused by this line which is called after the code I pasted:
PrefabUtility.SetPropertyModifications(gameObject, modList.ToArray());

So the problem I was tackling half of the day turned out to be ridiculous. At least I hope someone gets a little laugh out of that :smile: Apologies for polluting the forum with problems caused by rookie mistakes :slight_smile: