I have 2 scene’s “A” " B"
in Scene “A” there is a Button to click then a new scene is loaded Scene “B”
I also have a GameObject (Prefab) I want to Instantiate into Scene “B” when I click that button.
This is where Im having the problem? The scene B loads and so does the gameobject but the gameobject disappears right away and doesn’t stay in the Scene?
Script form Scene “A” (scene B is empty except for a default camera).
var LoadMyObject : GameObject;
function OnGUI ()
{
if (GUI.Button (Rect (248, 110, 103,27), “”, “button”))
{
Application.LoadLevel(9);
Instantiate(LoadMyGameObject, Vector3(0, 0, 2), Quaternion.identity);
}
}
When I click the button from scene A, scene B loads and the gameobject appears for a split second. What am I doing wrong, so that the game object doesn’t disappear right away and actually stays in this scene?
Thanks
Could you please wrap your code in the code tags ie: [ code] [/ code] without the spaces!
Does the game object have a rigidbody? It may be falling do to that.
Im wondering ifnthe game object is being instantiated in scene a and then being destroyed by the scene b load finishing…
Hello killer, I sure can wrap it in code tags:
var LoadMyObject : GameObject;
function OnGUI ()
{
if (GUI.Button (Rect (248, 110, 103,27), "", "button"))
{
Application.LoadLevel(1);
Instantiate(LoadMyObject, Vector3(0, 0, 2), Quaternion.identity);
}
}
The gameObject does Not have a rigidbody and I know its showing up but just disappears? Im now thinking its getting instantiated in Scene A instead of Scene B? But Im not sure (may just be lag?)
Ive attached a simple project to demonstrate Called testDrive which just has the script a button, 2 scenes (A B) and a Cube as my gameObject.
If theres another way to achieve this Im all ears 
Any help is appreciated!
425414–14760–$testdrive.zip (56.2 KB)
Is there another way to use the button in scene A, to load scene B but also instantiates a prefab of my choosing into scene B?
I just cant think of another way to do it and Im not that experienced with code but doing my best.
Ya, the thing is being instantiated before b finishes loading. It seems like you want the thing to be instantiated right when the second scene loads, so maybe make a script that has the instatiate on the Awake() function, and put that in scene b.
hey Killer,
Yes using the Awake () function and creating new script in the other scene did work But is unfortunately not going to work for my situation, I think I over simplified the question hoping to get the right solution but let me try and explain it better with a new scene and an image.
I really appreciate the help!!! The attached example has 3 scenes with 2 buttons and the a scene called “Newscene” which is where Im trying to get it to click the button and instantiate a certain cube in the new scene. Im totally stuck and this is a better example my real game has about 20 of these scenes so you can see my dilemma.

426353–14781–$newscene.zip (102 KB)
Maybe give the prefab a DontDestroyOnLoad() funtion. Then destroy them with code when need be.
TOTALLY AWESOME!!! Killer You are the Man! Thank you very much!
Ive been searching for I dont know how long lol Again THANK YOU!
In addition to killer1390’s solution, you could make a function for loading levels and add “yield Application.isLoadingLevel;” which will instruct the code to wait until the level is fully loaded. Coroutine (yield) calls do not work inside built-in functions like Update(), OnGUI() etc.
var LoadMyObject : GameObject;
function OnGUI ()
{
if (GUI.Button (Rect (248, 110, 103,27), "", "button"))
{
LoadLevel();
}
}
function LoadLevel() {
Application.LoadLevel(9);
yield Application.isLoadingLevel;
Instantiate(LoadMyGameObject, Vector3(0, 0, 2), Quaternion.identity);
}