Prevent Property from Serializing In Prefab but not on Instances

Trying to figure out if there’s a way to prevent prefabs from receiving “apply” on certain variables in a script? I want it to have a property with a default value, but when I edit an instance in the scene and click “apply” the field stays bold and doesn’t save to the prefab? Possible?

I’ve been trying to figure this out as well. It would be great to have a flag like [System.NonSerialize] to make a public variable non-prefab serializable. I come across this use case very often; where many prefab instances have 99% of the same setup, but need some scene specific tweaking. Making those changes is risky because someone hitting apply prefab will wipe them on all instances.

Came across this problem recently. Try this:

using UnityEditor

[ExecuteInEditMode]
public class DontCommitPropertyA : MonoBehaviour, ISerializationCallbackReceiver 
{
  public string PropertyA;
  public string PropertyB;

  OnBeforeSerialize() 
  {
    if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.Prefab)
    {
      // Here you can reset values if the object is a source prefab
      PropertyA = "";
    }
  }
  
  OnAfterDeserialize()
  {
  }
}

You may want to wrap some of this code with ifdefs for runtime. This works for me :slight_smile: