# repeat object spawn

**URL:** <https://discussions.unity.com/t/repeat-object-spawn/5742>\
**Category:** Questions & Answers\
**Created:** [July 19, 2010, 8:23pm UTC](https://discussions.unity.com/t/repeat-object-spawn/5742 "2010-07-19T20:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon75386872](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@anon75386872](https://discussions.unity.com/u/anon75386872)\
**Post date:** [July 19, 2010, 8:23pm UTC](https://discussions.unity.com/t/repeat-object-spawn/5742/1 "2010-07-19T20:23:57Z")

</div>

How do I make a prefab spawn repeatedly? Here's my prefab spawn script

```auto
var evilsphere : Transform;

function Start () {

yield WaitForSeconds (1); Instantiate (evilsphere, transform.position,
transform.rotation); 

} 

```

---

<div class="post-metadata">

**Author:** ![Eric5h5](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/eric5h5/32/44225_2.png) [@Eric5h5](https://discussions.unity.com/u/Eric5h5)\
**Post date:** [July 19, 2010, 8:52pm UTC](https://discussions.unity.com/t/repeat-object-spawn/5742/4 "2010-07-19T20:52:56Z")

</div>

Use InvokeRepeating:

```auto
var evilsphere : Transform;
var waitTime = 1.0;

function Start () {
   InvokeRepeating ("Spawn", waitTime, waitTime);
}

function Spawn () {
   Instantiate (evilsphere, transform.position, transform.rotation);
}

```

---

<div class="post-metadata">

**Author:** ![anon93786194](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@anon93786194](https://discussions.unity.com/u/anon93786194)\
**Post date:** [July 19, 2010, 8:45pm UTC](https://discussions.unity.com/t/repeat-object-spawn/5742/3 "2010-07-19T20:45:04Z")

</div>

This previous question answers your question:

[http://answers.unity3d.com/questions/14913/programming-help-with-instantiate/14934#14934](http://answers.unity3d.com/questions/14913/programming-help-with-instantiate/14934#14934)

---

<div class="post-metadata">

**Author:** ![StephanK](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@StephanK](https://discussions.unity.com/u/StephanK)\
**Post date:** [July 19, 2010, 8:31pm UTC](https://discussions.unity.com/t/repeat-object-spawn/5742/2 "2010-07-19T20:31:06Z")

</div>

The idea to use yield is correct. But you will have to use this in a Coroutine to work.

```auto
var evilsphere : GameObject;

function Start () {
  SpawnRoutine();
}

function SpawnRoutine () {
  while(true) {
    Instantiate (evilsphere, transform.position, transform.rotation);
    yield WaitForSeconds(1);
  } 
}

```
