Search Unity

Change prefab property in script without initialize and replace?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Thaina, Sep 12, 2018.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    204
    Even it doable in prefab UI itself. I could not found a way to do it in editor script. The only way I could change prefab property is initialize it and replace it and delete it after even though I just want to change only one property of all prefabs in my project (I want to change a material of all renderer of each children in every prefabs)

    Are there anyway we could do that?
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    597
    Load all your objects using whatever method you want, then loop through them, modify each object, and call
    EditorUtility.SetDirty
    on it. Then call
    AssetDatabase.SaveAssets
    when you're done.
     
    Thaina likes this.
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    204
    @Madgvox Thanks you for your answer but today I had update project to 2018.3 was released and it seem there was a new `PrefabUtility.SavePrefabAsset` function that was really doing the job now
     
    gresolio and Madgvox like this.
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    597
    Oh cool, thanks for the info. It's easy to get behind on API changes if you primarily work in older versions of Unity. :p