- Home /
Resources.Load() don't loads texture in standalone build, when in unityeditor it does
Hello everyone, I have a problem with my project, when I built a .exe for standalone game it works different than in unityeditor. In unity editor it works as it have to, it loads all textures correctly, but in standalone build it don't work correctly.
Application: Map browser - creating a map from lots of .JPGs witch are sorted by speciffed name. Creating a terrain, creating terraindata with loaded texture, in unity editor it works perfectly, all textures are at thier places, but in standalone build some textures are ok, but almost half of them are at wrong places and some of them are disorted.
My question is :why Resources.Load() loads wrong texture in .exe standalone, when in unityeditor it works great?? In unity editor it loads correct texture, but in standalone game it often loads a texture even from a different folder !! ( folders are in resources folder) For example: Resources/xxx/xxxyyyy;
Resources/zzz/zzzcccc; Resources/zzz/zzzkkk; where xxx and zzz are folders name and a part of texture file name which is in this folder, xxxyyyy, zzzcccc and zzzkkk are textures names
Code:
for (int i = 0; i < ilosc; i++) {
Terrain_data_list.Add (new List<TerrainData> ());
Terrains_list.Add (new List<GameObject> ());
for (int j = 0; j < ilosc *1.5f; j++) {
Terrain_data_list[i].Add ( new TerrainData());
Terrain_data_list[i][j].heightmapResolution = 1;
Terrain_data_list[i][j].size = new Vector3 (15, 1, 15);
Terrain_data_list[i][j].baseMapResolution =256;
SplatPrototype[] tekstura= new SplatPrototype [1];
tekstura [0] = new SplatPrototype ();
string path = kamera_sterowanie.skalowanie + @"/" + kamera_sterowanie.skalowanie + indeks_na_tekst(Oblicz_indeks(poczatek) + j + i * ilosc_kolumn);
tekstura [0].texture = Resources.Load (path) as Texture2D;
Terrain_data_list[i][j].splatPrototypes = tekstura;
Terrains_list[i].Add(new GameObject("teren "+i.ToString()+"x"+j.ToString()));
Terrains_list[i][j].AddComponent<Terrain>();
Terrains_list[i][j].gameObject.GetComponent<Terrain>().terrainData = Terrain_data_list[i][j];
Terrains_list[i][j].transform.position = new Vector3 (-ilosc/2*Rozmiar + j*Rozmiar, wysokosc_terenu, -ilosc/2*Rozmiar + i*Rozmiar);
}
}
where function Oblicz_indeks() calculates which file ( part of it's name) should be loaded and indeks_na_tekst() converts file index (name) to string. Kamera_sterowanie_skalowanie is a name of a direcotry where texture is and its first letters of texture name, for example: i have texture named xxxyyyy which is in directory xxx, where xxx is scale of the map and yyyy is a name which determines the location of texture (map fragment)(in latitude and longitude coordinates)
in a logfile i have a message: failed to get pixels of splat texture.
Im changed texture type to advenced and then checked the parmameter: Write/Read enabled, but Now the textures are just white and in logfile is message: TerrainData is missing splat texture 0.
I have created a delvelop build and attached it to visal studio what i have discovered is that a name (path) to the file that i want to load is correct, but unity don't find it and the result is NULL. Maybe unity trying to find it in wrong Resources folder or for some reason unity can't create a texture from a loaded file, but i think it shouldn't be null in that case? How can I get the path of resources folder that Im trying to load textures from? Soo the problem is in Resources.Load().
After use Application.dataPath Im know the resources folder is in applicationdata folder, but i cant look inside that, beacuse its a .asset file, and i can't examine a textures.
Strage is that it have loaded a textures (wrong and disorted, but anyway loaded it) but after i changed textture type to advenced and enabled Read/Write, application don't load (find?) the textures. In unityeditor it works great but in build it can't find/load the textures.
can you post a result of the whole path creation process? the string passed to load
Path is ok, the string named path which I put to Resources.Load() is : "500/50000123A011" I have a folder "500" in Resources folder, and in this folder (500) there is a file 50000123A011.png and its correct file i want to load. After use of Resources.Load(path), where path string is correct I get null as a result
UPTADED
I have loaded textures by creating it from bytes loaded from a .JPG file:
sciezka2 = Application.dataPath;
string sciezka = kamera_sterowanie.skalowanie + @"\" + kamera_sterowanie.skalowanie + indeks_na_tekst(Oblicz_indeks(poczatek) + j + i * ilosc_kolumn);
byte[] dane_z_pliku;
//tekstura [0].texture = Resources.Load (sciezka) as Texture2D;
if (File.Exists(sciezka2 + "/Resources/" + sciezka + ".JPG"))
{
dane_z_pliku = File.ReadAllBytes(sciezka2 + "/Resources/" + sciezka + ".JPG");
tekstura[0].texture = new Texture2D(2, 2);
tekstura[0].texture.LoadImage(dane_z_pliku);
}
else if (File.Exists(sciezka2 + "/Resources/pusty.JPG"))
{
dane_z_pliku = File.ReadAllBytes(sciezka2 + "/Resources/pusty.JPG");
tekstura[0].texture = new Texture2D(2, 2);
tekstura[0].texture.LoadImage(dane_z_pliku);
}
Debug.Log("Loading texture: " + sciezka + " textura: ", tekstura[0].texture);
Dane_terenu_wiersze[i][j].splatPrototypes = tekstura;
Teren_wiersze[i].Add(new GameObject("teren "+i.ToString()+"x"+j.ToString()));
Teren_wiersze[i][j].AddComponent<Terrain>();
Teren_wiersze[i][j].gameObject.GetComponent<Terrain>().terrainData = Dane_terenu_wiersze[i][j];
Teren_wiersze[i][j].transform.position = new Vector3 (-ilosc/2*Rozmiar + j*Rozmiar, wysokosc_terenu, -ilosc/2*Rozmiar + i*Rozmiar);
Anyway its still not solved, and im having the same problem when trying to load terraindata..
Answer by Eric5h5 · Dec 01, 2016 at 12:55 PM
Presumably you have >4GB of data, which isn't supported in builds with Resources.Load, since there's no actual Resources folder as such in that case, but everything is combined into a file. (Using 64 bit doesn't help.) Use AssetBundles instead.
So 4GB is the maximum resources limitation in Unity? Is it a personal test results or Unity claim it in documents? Thank you!