Skip to main content
added 201 characters in body
Source Link
qqqqqqq
  • 278
  • 3
  • 14

After the @DMGregory♦ comment I come across this documentation.

So, to have the changes made through the editor API serialized correctly I did change this way:

Undo.RecordObject(gameObjectInScene, "Set reference for itsField.");
gameObjectInScene.itsField = theFieldValue;
PrefabUtility.RecordPrefabInstancePropertyModifications(gameObjectInScene);

And if after changing the field you would like to apply the field change to a prefab just add a fourth line:

PrefabUtility.ApplyPrefabInstance(gameObjectInScene, InteractionMode.UserAction);

After the @DMGregory♦ comment I come across this documentation.

So, to have the changes made through the editor API serialized correctly I did change this way:

Undo.RecordObject(gameObjectInScene, "Set reference for itsField.");
gameObjectInScene.itsField = theFieldValue;
PrefabUtility.RecordPrefabInstancePropertyModifications(gameObjectInScene);

After the @DMGregory♦ comment I come across this documentation.

So, to have the changes made through the editor API serialized correctly I did change this way:

Undo.RecordObject(gameObjectInScene, "Set reference for itsField.");
gameObjectInScene.itsField = theFieldValue;
PrefabUtility.RecordPrefabInstancePropertyModifications(gameObjectInScene);

And if after changing the field you would like to apply the field change to a prefab just add a fourth line:

PrefabUtility.ApplyPrefabInstance(gameObjectInScene, InteractionMode.UserAction);
Source Link
qqqqqqq
  • 278
  • 3
  • 14

After the @DMGregory♦ comment I come across this documentation.

So, to have the changes made through the editor API serialized correctly I did change this way:

Undo.RecordObject(gameObjectInScene, "Set reference for itsField.");
gameObjectInScene.itsField = theFieldValue;
PrefabUtility.RecordPrefabInstancePropertyModifications(gameObjectInScene);