Custom Unity package containing system to load/request new scenes.
Derived from the Unity Open Project, Chop Chop.
-
Import the
Scene Management Samplesample into project. -
Inside of the generated
SceneManagementSetupfolder, do the following:- Make a path to
Assets/ScriptableObjects/SceneManagement; select theEventsandSceneConfigsfolder and place them inside this SceneManagement folder. - Mark both the
EventsandSceneConfigsfolders as Addressable on the top of the Inspector window. - Move the contents of the
Prefabsfolder toAssets/Prefabs/SceneManagement.
- Make a path to
Note:
- You will need to add a
SceneConfigScriptableObject asset for each new Scene you create, so be sure to add them to thisSceneConfigsfolder to ensure they are automatically setup to be addressable.
- Create a folder called
GameScenesinside yourScenesfolder. - Move the
ManagersScenescene into this folder. - Mark this folder as Addressable. All new game scenes should be added to this folder.
The imported sample includes a ManagerScene scene and a ManagerSceneConfig asset.
The intent of this scene is to house any scripts that should exist in perpetuity throughout the lifetime of your game. At a minimum, this contains SceneLoader script (housed in a prefab in the sample version of this scene). This may also include:
- AudioManager that serves as the single source for playing audio.
Note:
- This scene, and its corresponding Config asset, will need to be configured similarly to the actual scenes of your game, as outlined below under Setting up a New Scene.
This scene is what your build loads into, and immediately loads in the Manager Scene and additively loads in the first scene of your game loop.
- Move this scene into the top level of your Scenes folder.
- Add Initialization to your Build Settings; it will be the only scene in your project's Build Settings due to the nature of how the remaining scenes are loaded through the Addressable system.
- On the
Initializerprefab, add theSceneLoadConfigSOasset of your game's starting scene; MainMenu, etc.
Note:
- This scene, and the folder it is in, should not be marked as Addressable.
- Make your new scene file as you would normally.
- Place the scene into the
GameScenesfolder. - Create a new
SceneConfiginside of theSceneConfigsfolder discussed above; follow naming convention of "SceneNameConfig". - Select the new config asset; add the Scene file to the
SceneReffield.
Notes:
-
This variable takes in an AddressableAsset type, so you will be able to add your scene file if it is either marked as addressable or in a folder that has been marked as addressable, hence the setup of the GameScenes folder above.
-
This process needs to be followed for the ManagerScene scene and the ManagerSceneConfig asset that was brought in through the sample.
- Add the SceneLoadRequester prefab to the scene you want to load from.
- Call
SceneLoadRequester.Request()with the SceneConfig belonging to the Scene that you want to load (this can be done directly via another script, but is commonly done through a UnityEvent).
- Add in the EditorInitializer prefab into the scene you are working in.
ManagerSceneandEditorStartEventSOshould already be populated; add theSceneLoadConfigSObelonging to the given scene you are in.