Editor script to change inspector variables and notify prefabs

Hello, I have a script that helps me set inspector values for various prefabs I have. The format is something like this

public class Tools : MonoBehavior
{
    public MyScript myScript;

    [ContextMenu("Editor_Setup")]
    public void Editor_Setup()
    {
        myScript.myVariable = 3;
    }
}

This works fine, and I can call the piece of code while being in editor mode and right clicking on my Tools component->Editor_Setup. However, with prefabs, they aren’t notified that the value is changed (the value doesn’t become bold indicating that it changed), and this causes issues with nested prefabs and prefab variants.

Is there some function I can call that changes some inspector value just as if I manually clicked in it and inputted my own value?

Thank you in advance :slight_smile:

PrefabUtility has a number of method to work with overrides. However, in this case it might be simpler to use SerializedObject/SerializedProperty to update the variable and then set SerializedProperty.prefabOverride.

1 Like