How to access the data of one Scene in other Scene

Hi Everyone,

I am Very new to this Unity(iPhone). :shock:

I am writing my game menu. soo
I created two scenes
Scene1 : menu.
Scene2 : game.
respective scripts also (menu.js,game.js).

now , i have one function which will return a integer value in menu.js.
I am trying to access that data in game.js
(here be-careful :roll: )both are two different scenes .

I gone through the forums , they are saying like create one more script globals.js in common to both the scenes. here i didn’t get the point of COMMON.
My Question is :
Scene to Scene DATA PASSING
(I know accessing data between scripts those are belongs to same scene )
any help please


Thanks&Regards

You can store values in PlayerPrefs in one scene and read them from the next.

Or you can have a GameObject that is DoNotDestroyOnLoad, which will exist after you switch scenes. On this object you have a script, which stores the values.

Hi ,
I created a new Empty object .
i attached a script to that(globals.js) .
from game.js I am sending data to globals.js
from there I am trying to access them in main.js

but it is giving me the error like this

NullReferenceException : Object reference not set to an instance of an Object .

any more this i need to do .

Thanks

It is working fine with “playerprefs”.

but not working with the second method .

when you leave the level the object is beeing removed unless its set to dontdestroyonload

and even if you set it to dontdestroyonload, keep in mind that objects that are referenced in that object won’t be save, each object thats meant to survive must call dontdestroyonload on its own

changing one scene to other scene is easy
before loading new scene u have to call destroy method
this is basic problem for beginners… i think u have to learn more about unity 3d … if u want any help feel free to mail me

just to clarify, I think referenced objects will survive, but gameobjects won’t.

Another option is putting the things you want to persist in static variables of a class.