Search Unity

Loading Prefabs from path [Strange Behaviour]

Discussion in 'Immediate Mode GUI (IMGUI)' started by Martin_Gonzalez, Jul 12, 2016.

  1. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Hi people! I'm starting developing some editor tools to create a lib and i have one strange behaviour with something in particular.
    I'm creating a simple inspector tool that shows me all the prefabs and when i click on one of them it creates an empty gameobject and inside a prefab (so i dont have that prefab into prefab problem)
    Everything works great, the list its ok and shows every prefab in a specific folder but when i change the prefab in the scene and i hit apply i get a duplicated item in the list.
    I will leave screenshots so you can see it more clearly

    Step one:
    I see my prefabs list, you can see the folder Cubes and the list of prefabs on the levelEditor
    https://postimg.org/image/dg26new87/

    Step Two:
    I created an object containing the prefab Cube1
    https://postimg.org/image/49ohdvgdj/

    Step Three:
    I modified the prefab adding a cylinder inside of it and hitting apply, the the object is duplicated in the list
    https://postimg.org/image/aoniajn3b/

    I'm using this to load all assets of a path

    Code (CSharp):
    1. public static Object[] LoadAllAssetsAtPath(string path)
    2.     {
    3.         if(path.EndsWith("/"))
    4.         {
    5.             path = path.TrimEnd('/');
    6.         }
    7.         string[] GUIDs = AssetDatabase.FindAssets("", new string[] {path});
    8.         Object[] objectList = new Object[GUIDs.Length];
    9.         for (int index = 0; index < GUIDs.Length; index++)
    10.         {
    11.             string guid = GUIDs[index];
    12.             string assetPath = AssetDatabase.GUIDToAssetPath(guid);
    13.             Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)) as Object;
    14.             objectList[index] = asset;
    15.         }
    16.         return objectList;
    17.     }