[EDITOR] Changed prefab values are reverting if I restart Unity.

Hello! I’m reassigning some sound effects to some NPCs. How can I get this to stick? I run an editor script, and the inspector shows the AudioClip[ ] on the Prefab. However if I press play or exit/restart Unity, the AudioClip[ ] goes back to what it was previously.

Is AssetDatabase.SaveAssets() not the way to get this value to stick?

AssetDatabase.SaveAssets();
UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(prefabPath);
try
{
  // We successfully loaded our prefab.
  GameObject go = (GameObject) o;
  Npc npc = go.GetComponent<Npc>();
  if (npc != null)
  {
    Debug.Log("Setting get hit on " + npc.name);
    // Attempting to overwrite prefab value here!
    npc.m_getHitSfx = new AudioClip[] {newGetHitSfx};
    Debug.Log("Sound applied is now " + npc.m_getHitSfx[0].name);
  }
}
AssetDatabase.SaveAssets();

Set dirty!

1 Like

Ah there it is! I thought there might be a dirty flag but couldn’t find it >.> Thanks again for your help hpjohn!