Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Replacing prefab in editor

Discussion in 'Scripting' started by reddotgames, Sep 15, 2012.

  1. reddotgames

    reddotgames

    Joined:
    Apr 5, 2011
    Posts:
    705
    Hello,

    I have script that generate mesh <name:testmesh> in editor mode, than I'm creating and replacing prefab in assets folder <testmesh.prefab>.
    All works ok for one prefab on scene. When I duplicate this prefab and changes one on them in scene in editor (by script that generate mesh), one prefab (which ive changed) is ok, another one - gets missing prefab and become red color.

    My code for creating prefab :

    var prefab = PrefabUtility.CreateEmptyPrefab("Assets/SmartWheel/" + target.uniqueName + ".prefab");
    PrefabUtility.ReplacePrefab(target.gameObject,prefab,ReplacePrefabOptions.ConnectToPrefab);

    I assume that ReplacePrefab delete connection between all scene prefabs and connect it back only to prefab that is modified. But how can I make it works?

    Manually finding connections in current scene is not good too, because I wanna changed prefab work in other scenes too.

    Thanks for tips