Keep a Texture2D while loading a Level

Hi everyone,

I use to load some Textures via WWW object into a Texture2D variable.
When I Load a new Level using Application.LoadLevel(), it gets deleted, even if the script the variable is in “survives” because of DontDestroyOnLoad().

I want to soehow keep the value of this variable while changing the level, but neither DontDestroyOnLoad(pic) nor making the variable static works.

Is there a way to do that?

Thanks in advance

I think you need to call DontDestroyOnLoad on both the texture and the script.

I did, but that didn’t help.
Weird.

If you haven’t already done so, try calling DontDestroyOnLoad on a variable assigned from www.texture rather than the property itself:-

var tex = [url]www.texture;[/url]
DontDestroyOnLoad(tex);

Aaaah, that’s it.
It took a while to understand, but that’s the trick.

Thanks a lot :smile: