0
\$\begingroup\$

I'm making a 2D game. In my StreamingAssets folder I have a JSON file with some info about inventory items (id, description, rarity, name, is stackable or not) and a png file which contains a pixel map (128x32) of the level I want to load after a first scene (this is from Quill18's tutorial: https://www.youtube.com/watch?v=5RzziXSwSsg , basically a specific color corresponds to a specific prefab. An object reads through all the pixels and then spawns the level). The fact is that I have issues with both these elements when the game is built (everything works perfectly in the game window in Unity): the inventory items don't collide with the player and the level is not loaded.

This is the code that gets the image name

public string levelFileName;
string filePath = Application.dataPath + "/StreamingAssets/" + levelFileName;
byte[] bytes = System.IO.File.ReadAllBytes (filePath);
Texture2D levelMap = new Texture2D (2, 2);
levelMap.LoadImage (bytes);

And the pickable objects basically have a collision detection script and have a specific ID, so that when they collide with the player, the inventory adds in a free slot an image with the specs correspondant to that ID (i.e. ID=1 then it's an health potion, is stackable, it's not rare and so on). Everything else works fine in the game. Do you think that the issue is linked to the StreamingAssets folder (first time using it) or is it just a coincidence? And also could you help me solve the problem? Thank you in advance for any kind of help.

Edit: my Player logs:

enter image description here

\$\endgroup\$
1
\$\begingroup\$

To me it looks like part of the code was simply not executed due to an error. You should get the logs for your build and check if you do not have any error.

You should not assume that because you do not have errors in the editor you will not have any in the build.

You can find the info here : unity logs

EDIT :

The streaming asset path might change depending on the platform you are building to or on the version of Unity you are Using you should use

Application.streamingAssetsPath

instead. All info here : Streaming assets path

\$\endgroup\$
  • \$\begingroup\$ Hi, thank you for your answer. It looks like you put me on the right track. I updated the question adding the screenshot. I named the build UntitledDelete just to test things out. If I'm reading this right, it looks like it can't find the files I'm referencing. Can you help me further? \$\endgroup\$ – Jules Oct 30 '16 at 7:42
  • \$\begingroup\$ What platform are building for? Linux? \$\endgroup\$ – Géry Arduino Oct 30 '16 at 8:15
  • \$\begingroup\$ In the build settings I selected "PC, Mac & Linux Standalone", but I'm playing and developing it on the Mac \$\endgroup\$ – Jules Oct 30 '16 at 8:19
  • 1
    \$\begingroup\$ I edited my answer to include what i think is the actual solution. \$\endgroup\$ – Géry Arduino Oct 30 '16 at 8:43
  • \$\begingroup\$ Thank you so much for your help, you solved a problem I had been working on for a week now! \$\endgroup\$ – Jules Oct 30 '16 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.