AssetDatabase not working on Build
Hello,
I hope someone can help me with this. I don't have a lot of experience with Unity and I have been using this code to load different models into my scene:
target = AssetDatabase.LoadAssetAtPath(myPath+"figure_"+number+".obj", GameObject);
But when I am about to build the project the console says:
"Assets/Script/modeloGenerico.js(56,18): BCE0005: Unknown identifier: 'AssetDatabase'."
I need to load the models of a folder depending on different conditions. Is there any code I can use for this?
Thanks everyone!
Answer by Positive7 · Sep 17, 2015 at 12:30 PM
AssetDatabase is for Editor only. http://docs.unity3d.com/ScriptReference/AssetDatabase.html
Put all your obj to Resources folder and use Resources.Load()
; http://docs.unity3d.com/ScriptReference/Resources.Load.html
Thank you so much!
I have been substituting everything I needed and it works perfectly!
You're very welcome. $$anonymous$$eep up the good work!
Do you also happen to know how to check if a file exists?
I was using System.IO.File.Exists("file01.obj")
and I need to change it too. I haven't been able to find another solution yet.
System.IO.File.Exists("")
should work unless you building for webplayer.
System.IO.File.Exists(Application.dataPath + "Resources/file01.obj")
or
System.IO.File.Exists(Application.dataPath + "Assets/Resources/file01.obj")
or something like that I'm typing this from mobile and I don't remember. You can check it with Debug.Log if path is right. Debug.Log(Application.dataPath + "Assets");
hi.actually the correct file path is:
System.IO.File.Exists(Application.dataPath + "/Resources/file01.obj");
you just missed a /. @Positive7
Answer by Sellene · Sep 18, 2015 at 01:11 PM
I guess might have not been using it correctly. I am eager to try it as soon as I finish with something else. I will let you know when it works. Thanks again!
Your answer
Follow this Question
Related Questions
Is it possible to change a built projects name when running? 1 Answer
After Build Scripts no longer functioning in build or editor 1 Answer
What reason could there be, if a parent object refuses to take the new given position? 0 Answers
switch name.contains 0 Answers
I am having scripting errors before I even type anything in 0 Answers