Call function in another scene?

Hello. question 1: How can I call function in GameObject’s script in another scenes? question 2: Exist in unity global script? For manipulation with global data for collaboration many scenes? Please excuse my bad English. :slight_smile:

Hi

  1. All your scene may use the same scripts. They even share all the assets of the game.

  2. You may save data from a scene to another via PlayerPrefs or via a custom save/load system.

1.- you can use Object.DontDestroyOnLoad and set an object in the beginning that way you can have an ethernal gameobject living no matter if other scenes are loaded,until you manually destroy it

2.- you can have a game manager which stores all the game relevant information in a custom non mono behaviour class with static methods that will stay live as long as the game is running

3.- you use playerprefs to save data to registry in windows or to a individual file in the library folders in osx, you can save all relevant information to playerprefs before the loading of a next scene and load it back when you are already in the next scene

i myself prefer some kind of singleton class not based on monobehaviour where i can store all my info and that can live for long periods of time no matter which scene is loaded

hope this helps

1 Like