Mark gameobject field as changed from prefab

I have a gameobject in a scene which is an instance of a prefab. Using some custom editor code, I can copy the position of a “door” and paste it into another door object.

Copying the door position…
125094-copy.png

Pasting the door position…
125095-paste.png

When I paste the position, the code is just setting the “Exit Position” field of the prefab.
alt text

So back in the scene, the gameobject does not recognize that the field has changed. The scene does not recognize that something has changed either…
alt text

Because of this, I can’t save the scene with the new changed values unless I go in and change them manually, so upon leaving the scene the values will revert. Is there any way I can indicate to the editor that the values have changed?

Maybe you can use this call: Unity - Scripting API: SceneManagement.EditorSceneManager.SaveScene

Here’s the modified code implementing a solution I found using the SerializedObject and SerializedProperty classes, which were just what I needed.

Passing in a component into the SerializedObject constructor, you can then use the object to call the FindProperty method and get the field you wish to change (and have the editor recognize the change.) Then using the SerializedProperty instance, set the corresponding datatype field in the SerializedProperty to the value you want and then call ApplyModifiedProperties() on it. I know it’s bit wacky, but it works great for what I needed to do. Now after using the “Paste Door Position” the values will be bold, the scene will be saveable, and the values will persist.
125166-capture2.png