- Home /
Are sprites reference (script) loaded every time?
Hi guys, we're developing a game for mobile phone and we're wondering about what is loaded and what is not.
Our game has 4 regions, and each region has 3 maps. Each region has his texture atlas. We have a master script that has ALL the sprites reference for each region and map. For example, if you're on map "1" the wall changes the sprite from "wall_castle" (by getting a reference from this script) but if you're on the map 2, the wall changes the sprite from "wall_town" and so on. Does unity load all atlas or only the used one? We're really worried about that. Thank you for your help ^^
[Sorry for the bad english and explanation]
Hi First of all thanks a lot for the great question. I am not very much AAA level experienced in Unity but as far I know that is :
Its depend upon how you are loading the references the texturing into the game: Generally, there are 2 ways (I think there are only 2 ways except asset bundle).
Either you need to make a public variable which contains all the atlas then you can load from that.
Or you load the atlas at the runtime from the resources.
Now question is which one is heavy ( in terms of $$anonymous$$emory Load)
If you have the public references then at starting of the scene all the atlas will comes into the memory because the CPU know that you can assign any texture any time ..so need to reference all the atlases. Example : I will give you $$anonymous$$e example. I have 5 rooms in my game. User need to select from scene 1 that which room he want to go.. then as per his selection scene 2 loads that room . I have assign all the rooms publicly in my game. Like
public GameObject[] rooms;
// then at Start() I load the respective room Instantiate( room[selectedIndex]);
Now when I build and select the any of the room and tap on the play button .. $$anonymous$$y game got crashed every time. I was think a lot the reason .. then I came to know that $$anonymous$$y public variable is creating the issue .. Because when I assign a single room to that public room the game run smoothly. NO crash.
To solve that I used the references from Resources folder.. After that game now I used Resources approach in my every game.
But now few days back I came to know that Resources folder remain in memory when game is running i.e. Unity doesn't know that you need to load which assets at what time ..so he keep references of all the resources assets at anytime/everytime.
Now my few days back statement is saying me that the publicly assigning references is much better because when the scene switches they will drop the UN-necessery references , or , previous & forth co$$anonymous$$g references.
So, In conclusion I didn't provide you any result .. but I have share all my experience with you.. WHICH SAYS THAT IT DEPENDS UPON THE TYPE OF ASSETS AND USE OF ASSETS IN GA$$anonymous$$E
Hope someone will clear this picture more.
Thanks for reading this all :)
Thank you for your awesome reply. I understood a lot, and I think that we'll keep using the sprite reference way.
Thank you again, for your time writing and your well explained reply ^^ Have a nice day