Hi everyone!
I'm currently working on a project where we build a large world made of several tiles that I need to export in order to reimport them later on several distant devices. Each tile is made of a GameObject having a mesh renderer attached to, containing the models of the buildings, and a child object containing the mesh of the ground.
These tiles are created through a script I made, which imports the model (as .DAE files) and instantiates a GameObject on my scene with all the corresponding materials/textures (specified in the .DAE). The corresponding line on my script is:
var go : GameObject = Instantiate(Resources.Load(meshName));
then this gameobject is the parent object and automatically has the ground mesh attached to.
Here is the list of the materials attached to the instantiated scene object I want to export:
![alt text][1]
Now that my tiles are correctly created, I need to export them so I wrote a script that generates a prefab for each parent GameObject:
function generatePrefab (initialGO : GameObject){
//Generate the name of the prefab
var path : String ="Assets/Prefabs/" + initialGO.name + ".prefab";
//Create the prefab
var prefab = PrefabUtility.CreatePrefab(path, initialGO, ReplacePrefabOptions.ReplaceNameBased);
}
The issue is that my prefab has the correct objects attached to with the correct hierarchy and LOD group, but **all the materials are missing** as you can see in the picture below:
![alt text][2]
I tried to store the materials array of each renderer and reassign it to the prefab's renderers but it doesn't change anything. I also tried all the CreatePrefabOptions but I couldn't see any change.
I suppose the issue comes from the instantiation of the gameobject (so the materials by the way) but I couldn't find anything on the web and I can't see another way of doing it.
I hope that the English mistakes I made won't hurt anyone :)
Thanks in advance
Gunt
[1]: /storage/temp/24914-matsobject.png
[2]: /storage/temp/24915-matspref.png
↧