Default Scene Parents - mariaheine/Zenject-But-Wiki GitHub Wiki
One drawback to using scene parent contract names instead of ProjectContext to add bindings shared across scenes, is that you always have to remember to configure the scene hierarchy inside Unity to contain the correct scenes before running it. You can't simply open different scenes and hit Play like you can with ProjectContext. So to address this, zenject allows specifying a default value for the different contract names in cases where an existing value is not already loaded.
🏞️ To take our example from multi-scene editing in zenject, we'd like to be able to open Ship scene and immediately hit play without needing to place an environment scene above that first. To do this, right click in your Projects tab and select
Create -> Zenject -> Default Scene Contract Config
. Note that you will have to do this by right clicking on a folder named Resources for this to work.
After adding this you can click on the ZenjectDefaultSceneContractConfig
object and add any number of defaults by typing in contract names and then dragging in scene files from the Project tab into the Scene property. After doing this, you should be able to directly run the Ship scene and the default environment scene will automatically be loaded above that.
Note that the default scene for a given contract will also be used when using scene decorators
🔥 Note that this is an editor only feature. The default contract names will not be used in builds. In those cases you will have to explicitly load the correct parent scenes yourself in code.