- Home /
Loading asset from system path
Hello. I need to create model viewer, which will receive model name from command line and load it. Model format is .obj. I tried this:
private const string ModelPath = "c:\\M9.obj";
void Start () {
var modelBundle = AssetBundle.CreateFromFile(ModelPath);
if(modelBundle != null)
{
GameObject model = Instantiate(modelBundle.mainAsset) as GameObject;
model.transform.localPosition = new Vector3(0, 0, 0);
}
}
But with every sample model I received a same error: "Error while reading AssetBundle header!". When was I trying to load via WWW with "file:///" prefix, model text has loaded successfully, but when I call "CreateFromMemory", there are same error returns.
What I am doing wrong?
Based on the file extension "obj", is the file a model exported directly from a 3D modelling software like $$anonymous$$aya ? AssetBundle.CreateFromFile can only be used with AssetBundles which are created within Unity. AssetBundles are a way to pack assets/scenes into a single file. However those assets needs to be part of the project itself
Thanks, I already found .obj to Unity $$anonymous$$esh runtime convertion class in Wiki
Your answer
