- Home /
Instantiate loops until unity crashes...
Hey I'm trying to instantiate an object but all it seems to do is keep making clones until unity crashes. I only need 3 clones. What am I doing wrong?
void Start ()
{
rotation.x = Random.Range(-0.1600f, -0.2200f);
int startrot = Random.Range(0, 360);
transform.rotation = Quaternion.Euler(startrot, 0, 0);
// Array 0=0 1=1 ... 9=9
for(int i = 0; i < 10; i++)
{
myDegrees[i]=270-(36*i);
Debug.Log("InputArray" + myDegrees[i]);
}
for(int c = 0; c < 3; c++)
{
Instantiate(prefab, new Vector3 (37, 0, 0), Quaternion.identity);//as Transform;
Debug.Log ("c= " + c);
}
}
Answer by kevinmrn · Apr 06, 2013 at 11:33 PM
Hey SirVictory,
Thanks for your reply, I did the same thing as you just made a new prefab and restarded, and its fixed now. Just redid the prefab. The problem was that it just kept making clones in an endless loop for no reason. Bug? :).
Cheers man!
I suppose so :D Those kind of things happen every now and then.
Answer by SrBilyon · Apr 06, 2013 at 08:47 PM
Weird. I tried the spawning code from above, and don't seem to be having that problem.
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public GameObject prefab;
void Start()
{
for (int c = 0; c < 3; c++)
{
Instantiate(prefab, new Vector3(37, 0, 0), Quaternion.identity);//as Transform;
Debug.Log("c= " + c);
}
}
}
It spawns all three prefabs for me. Are you getting any warnings?
Answer by binoculars88 · Aug 21, 2017 at 01:44 PM
Maybe your script was attached to the initial prefab? Every copy got the script attached to them again, so they keep copying themselves...
Your answer
![](https://koobas.hobune.stream/wayback/20220613095824im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Clone Selector 1 Answer
How can I get the x position for the left(and right) of the screen? 2 Answers
How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 1 Answer
Assigning gameobject to an instantiated prefab through script? 2 Answers
How to Instantiate and change velocity 2 Answers