Search code examples
c#unity-game-enginebuild.obj

Importing Object working in Unity editor, error when running build project


I am trying to import a .obj file into my unity project at runtime. I used the framework SimpleOBJ to import this file.

When running the project inside of the Unity editor everything works as expected and the object gets imported and displayed.

However after building the project when I try to import the file I get an error and the .obj file does not get imported.

I've tried different methodes of importing, more closely resembeling the examples delevered with the framework, however this only complicated the code but did not fix my issue.

class ObjHandler : MonoBehaviour
    {
        public GameObject import()
        {
            filepath = FileBrowser.OpenSingleFile("*");
            WWW www = new WWW(filepath);
            return ObjImporter.Import(www.text);
        }
public void ImportObject()
        {

            ObjHandler handler = new ObjHandler();
            _gameObject = handler.Import();
             foreach (Transform child in _gameObject.transform)
            {
                 GameObjects.Add(new GameObjectModel(child.gameObject));
                Debug.Log(child.gameObject.name);
            }   
        }

Expected Result: https://i.sstatic.net/EoakM.png

Actual result (Error): https://i.sstatic.net/g4lSu.png


Solution

  • I found a solution to my issue.
    Turns out it was the Unity version that I was using that created the issue.

    After digging some more in the error log I found this error:

    WARNING: Shader Unsupported: 'Legacy Shaders/Diffuse' - Pass 'Meta' has no vertex shader

    So I tried upgrading Unity a couple of times.

    Eventually I used the Beta build: Unity 2019.2 0a11

    This version fixed the unsupported shader error and this fixed my standalone build error.