Adding a file on Resources folder (on Build)

Hello!

My Json file is not appearing in “FOTO_DATA/Resources”.

I’m using Resources.Load(...) and the file is in “Assets/Resources”. I used Debug.Log(Resources.Load(...)) to make sure the file is been loaded sucessfully.

The game has no problem in Unity Editor, but when i build it this error is shown:
Could not find file “C:\Users------\Desktop\FOTO_Data\Resources\relations.json”

When i paste relations.json on the folder the game works fine.

The code:

public TextAsset arquivoJson;

private void Start() {
fileJson = Resources.Load(“relations”) as TextAsset;
jsonString = arquivoJson.ToString();
relationData = JsonMapper.ToObject(jsonString);
}

Anyone can help me solving this?

Make sure everything is correct and matches proper caps and such. Your code itself seems fine, however, I do see you are loading into “fileJson” but then you are convert “arquivoJson” toString. That’s perhaps because you just dropped the file into the variable for testing.

Otherwise, I use the same code, just a different json asset, to do my json.

To get the contents of a TextAsset, you’d want to use aquivoJson.text or fileJson.text, not ToString(). ToString() will just give you the name of the file. I don’t think that’s the particular problem you’re having here, but it’s certainly a problem.

ToString returns the text as well. I use it in my current game and it works just fine. I have also used .text as well. They give the same results.

Huh… weird. That’s A) not how ToString used to work with TextAssets, B) inconsistent with how ToString works with literally any other UnityEngine.Object-based class, and C) not what the documentation for the function says (according to the docs, the TextAsset.ToString inherits the standard UnityEngine.Object ToString method). But, a quick test confirms that that is indeed what it does.

I’ve bugreported it as a problem with the documentation.

Ah, ic. Interesting to know. It does appear TextAsset overrides ToString(). I suppose .text is probably a better choice to avoid confusion.

Test below code:

public static JsonData itemdata;
private string jsonString;
private TextAsset file;

// Use this for initialization
void Awake () {
file = Resources.Load (“AreaInfo”) as TextAsset;
jsonString = file.ToString ();
itemdata = JsonMapper.ToObject (jsonString);
}