- Home /
Resource.load general question
Question: - I have a sprite named "sprite_1" that is referenced in a UnityScene. So when that scene is loaded, unity must load that sprite with it.
Now if i call Resources.Load("sprite_1") by script it will load that sprite again? So in memory will be 2 duplicated textures?
Every time i call Resources.Load("sprite_1") it seems its loading the sprite from scratch and is not cached internally by unity.
Problem: - If the sprite is an spritesheet splited using textpacker and my scene is referencing a lot of sprite from that spritesheet, how can i handle that if later i want to use sprites from that spritesheet by script, avoid to call Resources.load("that spritesheet") again?
Solution i can think of: - Let the designers set the Scene with the sprites from that spriteSheet. - Make scripts to know where are the sprites referenced in the scene. - Clear all sprites used in that scene. - Then when unity loads, load the sprite sheet, split it and put the sprites it into a dictionary. - Finally iterate over all scene and put the sprites by script. Using this method i would have control about the spritesheet and use it elsewhere without loading it more than 1 time.
Bon dia.
Parles català? No acabo d'entendre que preguntes, pots fer un comentari explicant el problema en catlà o castellà? $$anonymous$$erci!
Hola, Si, basicament es: - Treballant en una scena de unity on faig drag& drop dels sprites de la carpeta Resources als spritesRenderers(gameObjects). Quan aquesta scena es carregada, els sprites son carregats perque estan linkats.
Per tant, quan la carrega de la scena causara que els sprites es carreguin tambe a memoria(+1)
Si per altra banda si jo tambe vull utilitzar aquests sprites al codi, haig de fer un Resources.load(''.."). (+1)
El resultat es que tinc en memoria dos sprites iguals. Veritat?
Gracies
Doncs bona pregunta... si uses el resources.load, suposo que si que els tens carregat dues vegades. El que pots fer es assignarlos a variables publiques desde el inspector, aixi pel que tinc entes agafaras els que ja tens carregats...
Pero no em se prou per estarne segur...
Bona sort!