- Home /
I'm attempting to instantiate a prefab GameObject, but it just won't show up!!
I'm working on a basic arcade runner, and I'm simply trying to instantiate an obstacle (in the form of a cow, in case you were wondering). In any case, nothing shows up when I try to spawn the cow.
public class Spawner : MonoBehaviour {
public GameObject cowObstacle, fenceObstacle;
// Use this for initialization
void Start () {
Instantiate(cowObstacle, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Any help is much appreciated as I've looked everywhere without any success.
Any errors in console? Do you have this script attached to gameobject in scene?
Answer by Glurth · Feb 25, 2018 at 06:21 PM
The first step is to confirm your code is actually being executed. Put a Debug.Log("Instantiating Cow");
right before you call Instantiate. If this does NOT show up in the console when you hit run, it's not actually being called. (probably because you don't actually have a "spawner" in your scene to "start") If it DOES show up, something else is going on: let us know.
I've added the debug.Log(""), and sure enough it's not showing up in the console. How would I add the spawner script into the scene?
Add an empty object to scene, then drag the script to object in inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220612153421im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MonoBehavior.Start() called infinite times? 1 Answer
How do I reference a GameObject after finding its collider with Physics.OverlapSphere()? 1 Answer
Instantiating GO infront of player 2 Answers
C# 2d Instantiate object randomly around gameobject 1 Answer
Souls pickup mechanic (Like Dark Souls, BloodBourne) 0 Answers