- Home /
How can i transfer an object from scene1 and instantiate it in scene2?
I have a selection menu (scene1) where a user can choose between different objects that he wants to display on scene2. I want to achieve the following behaviour:
User selects an object from scene1
The selected object should be transfered to scene2 but not yet displayed
When user presses mousebutton, the object will be instantiated on the mouse position.
Can i achieve this by using MoveGameObjectToScene
?
Answer by Unity-Devloper · Jun 16, 2020 at 11:30 AM
You'll usually use prefabs for that purpose. So create a prefab from your in scene 1 and then simply put it into scene 2.
Just drag it into the scene ... when you change the prefab, yes it will affect the original one.
See also Prefabs Documentation
So, i have a list of prefabs in scene1. User presses on any of these objects and gets refered to scene2. How can i pass my selected prefab from scene1 to my "objectspawner.cs" script in scene2? I want the prefab only instantiated in scene2 depending on the selected prefab in scene1. Am i missing something or overthinking this?
You Thinking is on right direction !! But its It's hard to explain. so i can send a reference for that can help better.
https://answers.unity.com/questions/1297392/how-do-i-get-a-reference-to-an-object-in-another-s.html
If you don't understand !, you can ask without hesitation.
Thank You For Interest!!Have a Good Day
Answer by FrameXdropProvrex · Jun 17, 2020 at 06:12 PM
There's a method called DontDestroyOnLoad. If you call this in the Start method of your script (DontDestroyOnLoad(this)), it will stay in your hierarchy until you destroy the gameObject yourself, even when switching scenes.