2
\$\begingroup\$

I have some textures that are used in multiple scenes and I want to keep them in memory to speed up load times between scenes. I know about Resources.Load, but does that always keep it loaded? If a texture is loaded with Resources.Load, will instantiating a prefab with that texture recognize that it's already loaded or will it load its own instance of the texture?

It would be better if it's a method that I can use in code so that I can make a loading screen and not freeze everyhing up. I'm limited to an earlier version of Unity so I don't have access to LoadLevelAsyc.

\$\endgroup\$
2
\$\begingroup\$

Unity is pretty smart about keeping stuff around that you need in the future. What's more difficult is telling it when to get rid of stuff you don't need anymore.

So yes, once this texture is loaded, it will recognize that and not load it again provided something hasn't removed it from memory in the meantime.

\$\endgroup\$
0
\$\begingroup\$

If you are sure you want to keep it around, you can call DontDestroyOnLoad. See http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

If you set that, it will not be destroyed when the scene loads. Keep in mind that you are now explicitly in charge of destroying that object, as it won't otherwise go away. I would therefore make sure to track any object you mark as DontDestroyOnLoad, or you're likely to end up with memory leaks.

\$\endgroup\$

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.