Problem creating Assets from outside Resources directory

Hey I got following problem I generate assets at run time from outside the resources folder.

  1. It works on my computer.

  2. It does not work on any other computer.

  3. I use http://wiki.unity3d.com/index.php?title=ObjImporter to import the obj files.

Thats the code to load the model no error…

        if(File.Exists(path+"Model.obj"))
        {
            part.mesh = importer.ImportFile(path+"Model.obj");
        }
        else
        {
            InGameDebug.SetText("error file not found " + path+"Model.obj" + "\n");
        }

Thats the code that adds the mesh no error…

        part.AddComponent<MeshFilter>();
        part.AddComponent<MeshRenderer>();
        part.GetComponent<MeshFilter>().mesh = template.mesh; 
        if(part.GetComponent<MeshFilter>().mesh == null)
        {
            InGameDebug.SetText("error no Mesh" + "\n");

        }
        else
        {
            InGameDebug.SetText("Mesh created mesh vertices count = " + part.GetComponent<MeshFilter>().mesh.vertices.Length + "\n");//returns correct count

        }


any one got a idea what could be the problem ?

Pretty sure the answer lies in your “path” variable being setup for your computer, but incorrect for the other computer.

The weird think is that the path is ok he loads the stuff the first screenshot is from a mates Pc.

The icons to the top right are loaded from the same folder as the Model.obj.

I’ll ask the obvious question - why are you loading raw textures and models out of a directory instead of letting Unity do the work for you :slight_smile:

Mod support :stuck_out_tongue:

1 Like

Screenshot is very clear that the path is a complete mess.

“/Neutral/Hulls\07/Normal.png”

Still not a good reason :slight_smile:

Use asset bundles. OBJ format doesn’t support animation and you’ll get bad compression artifacts in your textures.

Looking at that wiki link you posted of the importer, this is the blurb that opens stuff:

       StreamReader stream = File.OpenText(filename);
       string entireText = stream.ReadToEnd();
       stream.Close();
       using (StringReader reader = new StringReader(entireText))
       {
           string currentText = reader.ReadLine();
etc...

Copy that to a small project and make sure THAT code can read stuff you want.

Also, think about perhaps if there are differences in line endings that are tripping you up from one OS to another.

Funnily enough Windows will actually take that since it doesn’t care which direction your slashes go

1 Like

Its doe to https://msdn.microsoft.com/de-de/library/system.io.directory.getdirectories(v=vs.110).aspx the path is ok like i told he loads other stuff from the same folder.

I would not use obj if i had animation in plan also i am using the uncompressed raw image.

Values from

    currentObject.transform.position
        currentObject.transform.GetComponent<MeshFilter>().mesh.vertices.Length
        currentObject.transform.GetComponent<MeshRenderer>().material.shader.name
        currentObject.transform.GetComponent<MeshRenderer>().material.name

in game.

3310662--257181--c.jpg

So its there but not visible for what ever reason.

If you’d let Unity import them then you’d already be done :smile:

I’m not trying to be a jerk. 5 years ago I had the exact same idea you did and then I spent more time dealing with stupid crap like this than I did making a game. Let the pipeline do the work for you.

Thx for the hints but its all planed out and its basically no big deal I also got it working I dont even know if that’s the problem like I told it works on my computer and it loads all the stuff on other computers he displays the icons he loads the xml files just the Model wont show up…

Ok found the reason but not the problem here the values from my pc.

currentObject is active = True
MeshRenderer is active = True
mesh name = E:/jass 0.5/jass0.5_Data/GameData/ShipParts/Neutral/Hulls/00/Model.obj Instance
mesh bounds Size = (1.0, 0.4, 0.9)
position = (6.8, 0.0, 11.7)
localScale = (1.0, 1.0, 1.0)
verticesCount = 324
normalCount = 324
uvCount = 324
shader name = Standard
texture dimension = Tex2D
texture height = 512
texture width = 512
material name = E:/jass 0.5/jass0.5_Data/GameData/ShipParts/Neutral/Hulls/00/ (Instance)

And the values from a mates pc
currentObject is active = True
MeshRenderer is active = True
mesh name = C:/Users/Gemuese/Desktop/jass 0.5/jass0.5_Data/GameData/ShipParts/Neutral/Hulls/00/Model.obj Instance
mesh bounds Size = (1000414,0, 375156,0, 866384,0)
position = (6,8, 0,0, 11,7)
localScale = (1,0, 1,0, 1,0)
verticesCount = 324
normalCount = 324
uvCount = 324
shader name = Standard
texture dimension = Tex2D
texture height = 512
texture width = 512
material name = C:/Users/Gemuese/Desktop/jass 0.5/jass0.5_Data/GameData/ShipParts/Neutral/Hulls/00/ (Instance)

Just check the bounds size my (1.0, 0.4, 0.9) his (1000414,0, 375156,0, 866384,0) what could cause this ?

Ok it works now short version I added CultureInfo.InvariantCulture to all float parses the ObjImporter from http://wiki.unity3d.com/index.php?title=ObjImporter got.

Explanations about what went wrong are in the links below.
https://stackoverflow.com/questions/5592950/why-do-i-get-a-formatexception-when-converting-a-string-to-a-float