Search Unity

Creating a Prefab from an object and I want to add the mesh as a child of that?

Discussion in 'Prefabs' started by MikeUpchat, Feb 27, 2021.

  1. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    I am creating a prefab from a Gameobject that has a procedural mesh, I can create the Prefab and also add the mesh as an asset to the database so it works just fine, and I can add the prefab back into the scene. The only issue I have is the mesh asset is not a child of the object prefab, how do I make it s. I create the prefab using:
    Code (CSharp):
    1. GameObject prefab = PrefabUtility.SaveAsPrefabAsset(newobj, "Assets/Prefabs/" + newobj.name + ".prefab");
    2.  
    And the mesh is saved:
    Code (CSharp):
    1. meshpath = AssetDatabase.GenerateUniqueAssetPath(meshpath);
    2. AssetDatabase.CreateAsset(mesh, meshpath);
    3. AssetDatabase.SaveAssets();
    4. AssetDatabase.Refresh();
    So how do I add the mesh as an asset but also so it is in the Object prefab?