- Home /
How do I hook up references using multi-scene editing?
I've been using Unity's multi-scene editing capabilities, which allows multiple scenes to be loaded at once, and this has been helping me stay more organized.
Let's say I have a "Game" scene that contains my actual gameplay, and another scene called "Game UI" that contains all of the UI that needs to be displayed in the "Game" scene; both scenes exist/are loaded at the same time. The "Game" scene components do not need to know about the existence of the UI, but the UI wants to get references to certain things in the "Game" scene in order to display it.
How should I go about setting up these references? Unity does not allow references to be hooked up in the editor across scenes, so should I just use GameObject.Find
on Start, or is there a better way? I was considering using C# events, but I've never done this, so, frankly, I have no idea what I'm doing.
Answer by Cornelis-de-Jager · Aug 30, 2019 at 06:00 AM
Short Answer
You can't reference other scenes. You can only work with what is in the current one.
Solution
Create everythign in one scene and place them under a single gameObject. Call it something like GameScreens or PermanentObjects.
Add a script to it that looks as follow:
public class PermanentObject : MonoBehaviour {
void Awake() => DontDestroyOnLoad(this.gameObject);
}
Have this be instantiated in the first scene you open only. It will be referenceable in every scene. It will go with you so to say when yo uchange screen.
This is sort of the answer I was looking for, but I noticed that it was better for me to create a "master" scene with my game managers, and use a static instance to reference them in the UI scenes. I think perhaps using DontDestroyOnLoad
may defeat the purpose of using multiple scenes to organize game objects.
Your answer
Follow this Question
Related Questions
UI Scene ending with Text 1 Answer
Multiple EvenetSystems in Scene - only have 1 after searching though 1 Answer
Issues with Google VR fading in scene,Google Cardboard black fade transition not working 0 Answers
Problems compiling DLL for use with Unity's current version (2019.2.0f1) 4 Answers
Worldspace UI in wrong position/scale after scene change 0 Answers