Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Updating prefab variable via script doesn't save override

Discussion in 'Prefabs' started by hololabs, Jan 8, 2019.

  1. hololabs

    hololabs

    Joined:
    Nov 15, 2012
    Posts:
    10
    Hi,

    I've come across an issue with prefab overrides and I'm wondering if there is a way to set a prefab to dirty in order to save overrides via script.

    I have a prefab that gets an id value changed via script. This id change isn't getting saved in scene nor being flagged as an override on the prefab.

    unity-prefab-override-1.PNG

    If I manually update the value on the prefab it registers as an override and I can save it within the scene.

    unity-prefab-override-2.PNG

    Is there a way to set this object as dirty in a script? or can I touch some other property that will flag it as dirty.

    Thanks,

    Amesh
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    3,550
    How are you setting it dirty?

    If you're using EditorUtility.SetDirty, that's been broken by design for ages, and you have to also manually set the scene dirty with the scene manager. Alternatively, use SerializedObject/SerializedProperty with ApplyModifiedPropertiesWithoutUndo.
     
  3. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,432
  4. hololabs

    hololabs

    Joined:
    Nov 15, 2012
    Posts:
    10
    Thank you! PrefabUtility.RecordPrefabInstancePropertyModifications was exactly what I was looking for.