Search Unity

  1. Unity 2019.1 beta is now available.
    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're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Change prefab property in script without initialize and replace?

Discussion in 'Extensions & OnGUI' started by Thaina, Sep 12, 2018.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    113
    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:
    522
    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:
    113
    @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
     
    Madgvox likes this.
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    522
    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