Objects destroyed between scenes (using Don'tDestroyOnLoad)

Scene A sets up a List using a prefab with a data script attached holding a bool Active ;-

Persistant.Add(  firstAidObject  );
Persistant[0].GetComponent<Equipment>().Active = true;
Persistant.Add( firstAidObject );
Persistant[1].GetComponent<Equipment>().Active = false;

Scene B checks those and reports both == false ;(

If I replace the above in Scene A with ;-

Persistant.Add(  (GameObject) Instantiate (firstAidObject)  );
Persistant[0].GetComponent<Equipment>().Active = true;
Persistant.Add( (GameObject) Instantiate (firstAidObject) );
Persistant[1].GetComponent<Equipment>().Active = false;

The list elements get destyoed between scenes with the error ;-
“The object of type ‘GameObject’ has been destroyed but you are still trying to access it.”

My Awake() contains the following and other data is persistent between scenes

DontDestroyOnLoad(transform.gameObject);"

I just want the List in Scene A to be accessible from Scene B - where am I going wrong?

By adding

DontDestroyOnLoad( Persistant[0] );

Fixed it but still don’t understand why. If anyone can explain this for my enlightenment I’d really like to understand :wink:

Thanks,
Andy

Basically your Persistent is saving the object data within Unity’s persistent path. Which allows data to be stored between scenes.

Thanks T!

I must read the manual more :wink:

No problem! :slight_smile: