rogers.wang
rogers.wang

Reputation: 456

Unity 4.6 AutoConvert fbx file to Prefab file bug?

i try many times, but failed, so i think maybe this is unity 4.6's bug;

Unity 4.6 Windows 7 64bit

Requirement:when i import the fbx file, auto generate prefab file.

step1 : 1 in OnPostprocessModel (Editor folder) 2 below 4 method all return null:

   string path3 = @"C:\Users\Administrator\Documents\test\Assets\Resources\Models\Item.fbx";
   object obj1 = AssetDatabase.LoadMainAssetAtPath(path3);
   object obj2 = AssetDatabase.LoadAssetAtPath(path3, typeof(GameObject));

   object obj3 = Resources.LoadAssetAtPath(path3, typeof(GameObject));
   object obj4 = Resources.LoadAssetAtPath<GameObject>(path3);

Upvotes: 0

Views: 1117

Answers (1)

MX D
MX D

Reputation: 2485

It is not a bug, you are just never finding your object. Because you are providing the wrong path.

all 4 functions you are running require your model to either be inside the Resources folder or the Assets folder. So you will want to use path names as following

Assets/Resources/Models/Item.fbx
Resources/Models/Item.fbx

also the unity wiki teaches us the following

Note:
All asset names & paths in Unity use forward slashes, 
paths using backslashes will not work.

Beside's that I don't think you should be using these functions, but you should be using the PrefabUtility instead. A good sample of this can be found on unity answers

 // Create some asset folders.
AssetDatabase.CreateFolder("Assets/Meshes", "MyMeshes");
AssetDatabase.CreateFolder("Assets/Prefabs", "MyPrefabs");

// The paths to the mesh/prefab assets.
string meshPath = "Assets/Meshes/MyMeshes/MyMesh01.mesh";
string prefabPath = "Assets/Prefabs/MyPrefabs/MyPrefab01.prefab";
// Delete the assets if they already exist.
AssetDatabase.DeleteAsset(meshPath);
AssetDatabase.DeleteAsset(prefabPath);

// Create the mesh somehow.
Mesh mesh = GetMyMesh();

// Save the mesh as an asset.
AssetDatabase.CreateAsset(mesh, meshPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// Create a transform somehow, using the mesh that was previously saved.
Transform trans = GetMyTransform(mesh);
// Save the transform's GameObject as a prefab asset.
PrefabUtility.CreatePrefab(prefabPath, trans.gameObject);

Upvotes: 1

Related Questions