- Home /
Referencing a gameobject in another scene
The solutions I found online do not suit my requirements so I decided to ask a question here.
Situation:
I have a player with the property dontdestroyonload() attached to him and is currently inside Scene A
I load a new scene, Scene B by interacting with a portal (just a random game object with a boxcollider to detect if player is within the portal range) lets call it portalA
Player does not get destroyed and is loaded into the new scene
Scene B has another portal object called portalB which I intend to have the player spawn at but when using scenemanager loadscene() function to load the scene, since player object does not destroy on load, his transform position will be where he left off in Scene A and obviously not at portalB which I will need to reference to get the coordinates for the transform position.
Assuming I intend to do multiple portals and getting the transform once I load the scene will be tedious using a method I am aware of (tags). Is there a way to get portalB which is inside scene B while I am still inside scene A before I step through portalA?
Answer by Zaeran · Apr 23 at 07:26 AM
You can't access anything from a scene that hasn't already been loaded. You can have multiple scenes loaded at once though, so you can load in Scene B, reference the portal, then unload Scene A when the player steps through
Hi thanks for the reply, may I know where to look on unitys documentation for loading multiple scenes? At the moment I'm using scenemanager loadscene() to load sceneB
Your answer
Follow this Question
Related Questions
How can I have several scenes running at the same time? 1 Answer
How Do I Link Different Scenes? 4 Answers
Change Scene keeping Character and GUI Canvas 1 Answer
Load Scene Bug 0 Answers
Can't find game object / script after scene re-enter 1 Answer