Search Unity

assetpostprocessor script replace dummy objects?

Discussion in 'Scripting' started by zergmouse, Mar 5, 2011.

  1. zergmouse

    zergmouse

    Joined:
    Jun 30, 2010
    Posts:
    216
    is it possible to replace objects on import with prefabs?

    So in an assetpostprocessor script I want to find all boxes named "X" and replace them with a prefab in my project folder.

    I currently have no problem finding the objects. Right now my script will find all the boxes named "X" and tell me they were found by printing that into the console. Ok so now once I have found those how do I replace them with a prefab?

    Here is my current code chunk (once the object is found)
    Code (csharp):
    1.  
    2.             if (propName.ToLower() == BoolAddAMXPanel.ToLower()  (bool)propValue == true)
    3.             {
    4.                 Debug.LogWarning("The method for AddAMXPanel is not complete");
    5.  
    6.                 var amxPrefab = Resources.LoadAssetAtPath("_Prefabs/AMX", typeof(GameObject)) as GameObject;
    7.                 if (amxPrefab == null){Debug.Log("Oh no amxPrefab is null!!!");}
    8.  
    9.                 var newObject = EditorUtility.InstantiatePrefab(amxPrefab) as GameObject;
    10.                 if (newObject == null) { Debug.Log("Oh no newObject is null!!!"); }
    11.  
    12.                 if (newObject != null)
    13.                 {
    14.                     Debug.Log("Attempting to replace object now...");
    15.                     newObject.transform.position = go.transform.position;
    16.                     newObject.transform.rotation = go.transform.rotation;
    17.                     newObject.transform.localScale = go.transform.localScale;
    18.                     newObject.transform.parent = go.transform.parent;
    19.                 }
    20.  
    21.                 //DestroyImmediate(go);
    22.                
    23.             }
    The output to the console says that the amxPrefab and the newObject are null. any ideas?
     
  2. juanelo

    juanelo

    Joined:
    Jan 28, 2011
    Posts:
    46
    Hi zergcow -- Did you ever manage to find a solution to this problem?