Hello everyone, I'm working on a script that utilizes AssetPostProcessor. I'd like to automatically create prefabs out of my imported FBX file by looking at its Game Object structure.It works up to a point; I attach mesh colliders and attach references to Mesh Collider's sharedMesh in scene but if I create a prefab out of it, I lost all Mesh Collider meshes. I'm collecting all Mesh Filters in certain criteria.Then create Go's, attach meshcollider component for all.then copy the mesh filters to mesh collider using: Code (CSharp): Mesh _sharedMesh = Mesh.Instantiate(_navMeshFilters[i].sharedMesh) as Mesh; MeshCollider _collider = newGameObject.GetComponent<MeshCollider> (); _collider.sharedMesh = _sharedMesh; That works in scene view but not if I create a prefab out of it. It is clear that I'm missing a step. Hope someone with more experience can point me to right direction.
It's only guess, because your description is confusing, but I think it's because you referencing to instantiated meshes, that exist only in memory, you need to reference fbx model's meshes or save your instantiated meshes as assets, and reference them to mesh colliders.
Thank you very much for your post. I was trying to keep my post short but it looks like, that made it confusing. I'm collecting all Mesh Filters in an array called "_navMeshFilters[]" thinking they're references from the fbx file's meshes. Here is the code responsible for preparing the GameObjects and building the prefab. Code (CSharp): void PrepareNavMeshes(Transform incoming_transform) { _navmeshfilters = incoming_transform.GetComponentsInChildren<MeshFilter> (); GameObject newPrefabGO = new GameObject(m_masterTransform.name+"_"+incoming_transform.name + "_nav"); for (int i = 0; i < _navmeshfilters.Length; i++) { GameObject newGameObject=new GameObject(); newGameObject.AddComponent<MeshCollider>(); Mesh _sharedMesh = Mesh.Instantiate(_navmeshfilters[i].sharedMesh) as Mesh; MeshCollider _collider = newGameObject.GetComponent<MeshCollider> (); _collider.sharedMesh = _sharedMesh; } //Create new prefab string newPrefabPath = assetImporter.assetPath.Substring(0, assetImporter.assetPath.LastIndexOf('/') + 1); newPrefabPath += newPrefabGO.name + ".prefab"; UnityEngine.Object existingPrefab = AssetDatabase.LoadAssetAtPath(newPrefabPath, typeof(UnityEngine.Object)); UnityEngine.Object newPrefab = existingPrefab ?? PrefabUtility.CreateEmptyPrefab(newPrefabPath); GameObject prefab = PrefabUtility.ReplacePrefab(newPrefabGO, newPrefab, ReplacePrefabOptions.Default); } I read on Unity Answers people having all sorts of problems while assigning meshes to Mesh colliders. Tried all their solutions but couldn't make it work yet.