DontDestroyOnLoad - Array Data Lossed In Attached Component

So I can’t really think of whats going on so I figure I would post something here.

What happening is we have a menu system that shows comics ahead of the levels playing. Unfortunately ‘uptake’ time is very important so we load our main menu gui elements in the package, and then we stream in our comic pages on load.

On our “Menu” game object, we have a manager script which publicly exposes an array of the below class.

We then link the below script components into those publicly exposed spots.

Whats happening is, on level change, they retain all their data BUT the textures all get wiped out.

using UnityEngine;
using System.Collections;

public class LevelComic : MonoBehaviour
{
	
	
	public string title;
	
public Texture2D defaultPage;
	public Texture2D[] pages;
	public bool[] loaded;
	
	private string baseStreamingPath = "./";
	public string[] comicPagesPaths;
	
	void Awake()
	{
		if (!(Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer))
		{
			this.baseStreamingPath = "my address base :smile:";
		}
	}
	
	void Start()
	{
		// Start caching the images outside of the load order of Unity's webstreaming
		StartCoroutine("loadImages");
	}
	
	void OnLevelWasLoaded()
	{
		
		/** MY ANNOYING HACK FIX TO HELP RIGHT NOW TILL I FIND OUT WHATS GOING ON **/
		
		if ( Application.loadedLevelName == "Main Menu" )
		{
			
			// Clear out the already loaded status
			for (int x = 1; x < this.loaded.Length; x++)
			{
				this.loaded[x] = false;
			}
			
			// Link defaults to avoid no images being shown
			// (basically now i cant stream in one of the assets so it
			// gets packaged with unity)
			
			this.loaded[0] = true;
			this.pages[0] = this.defaultPage;
			
			// Go get the images AGAIN!! *grumble*
			StartCoroutine("loadImages");
		}
	}
	
	
	IEnumerator loadImages()
	{
		// Slot counter
		int x = 0;
		
		foreach ( string path in comicPagesPaths )
		{
			// Check if we already have a texture in the slot
			if ( !this.loaded[x] )
			{
				
				// Start getting the texture
				WWW www = new WWW(baseStreamingPath + path);
				
				// Go get some coffee
				yield return www;
			
			
				// If there is an error just make sure we set the check to false
				if ([url]www.error[/url] != null)
				{
					this.loaded[x] = false;
				}
				else
				{
					// Assign texture to slot and record it being saved
					this.pages[x] = (Texture2D)[url]www.texture;[/url]
					this.loaded[x] = true;
				}
			}
			
			// Increment our slot
			x++;
		}
	}
}

It’s just an oddity that I cant think of whats causing, possibly some sort of texture clearing when you change levels? but then why does my menu still have its? I dont know … it just boggles me mind! The boolean array is left untouched! I’m going to keep reading about WWW class, maybe all data is not permanent when you read it! who knows … :expressionless:

Just looking for input.

UPDATE:

Tried using www.LoadImageIntoTexture to see if it was just the way i handled the texture, it did the same thing :frowning:

Call DontDestroyOnLoad for the textures themselves, too.

Unfortunately, that too isnt working :frowning:

static function DontDestroyOnLoad (target : Object) : void

I’ve got the parent object (being the menu manger) DontDestroy’d. It just seems weird its just the textures that are calling it quits. Maybe something to do with my manager structure? The menu game object, has a menu script on it with:

public LevelComic[] comics;

Glitch?

hi all …
the same strange thing happened with me too … i used the DontDestroyOnLoad() and it works well but the textures just gone!!! i do it for two groups of gameObject … one group is contained the character and the other is contain some assets … the character dontDestroy perfectly when i load the second level… but the assets texturs is missing when i use the dont destroy fnction … any idea what is happining here??? or any possible help to fix this issue ??

So you have a gameObject with your Menu script attached right? How does that then get linked to the LevelComic scripts? Are you making sure to call DontDestroyOnLoad() on the gameObjects that the LevelComic scripts are attached to? Does that public array of LevelComic on the Menu script contain non-null references after loading a level?

It’s possible I am totally misinterpreting your setup. :wink:

no no no … its another project … but the same proplem … the materials missing when using dontDestroyOnLoad function …???

Call DontDestroyOnLoad on the textures themselves–pass in actual references to the live textures you want preserved.

I ran in to this last week, and I made a blog post about a solution here:

http://waddlefarm.org/blog/?p=446