- Home /
LoadAssetAtPath
I cant get this to work right for some reason. I have tried Resources and AssetDatabase to run this from but keep getting a null object from it. This is in editor and not runtime. importPath shows up correctly but impObject returns a null object. Any ideas?
var prefabPath : String = assetPath.Replace(".fbx", "Prefab.prefab");
var importPath : String = assetPath;
Debug.Log(importPath);
var impObject : GameObject = Resources.LoadAssetAtPath(importPath, GameObject) as GameObject;
Debug.Log(impObject);
Found the issue. AssetDatabase works but you need to refresh it since it doesnt update on import. AssetDatabase.Refresh(); makes all the difference in the world.
Answer by doublethink · Jan 16, 2013 at 08:35 PM
Usage of LoadAssetAtPath is normally discouraged for most purposes. Instead create a folder named "Resources" and place any prefabs you need to load during runtime there and use
Resources.Load("prefabName");
see http://docs.unity3d.com/Documentation/Manual/LoadingResourcesatRuntime.html
Your answer
Follow this Question
Related Questions
Resources.LoadAssetAtPath not working in WebBuild 1 Answer
AssetPostprocessor reference to asset being processed? 1 Answer
Serializing a collection of ScriptableObjects to an ASSET file? 1 Answer
Could not load copied asset via AssetDatabase.LoadAssetAtPath 4 Answers
Change material with EditorScript 3 Answers