- Home /
script gets started two times
I have the following code:
public GameObject bullet ;
...
GameObject.Instantiate(bullet, transform.position + spawnDistanceBullet * transform.forward, transform.rotation);
bullet has one script assigned, now when I the code above is executed the script is executed two times. I have no clue why though, I added a shot counter - nope for every count I get 2 script executions. I also used GetInstanceID() two different IDs (number difference 20). I also disassigned the script, I get the following messsage two times:
The referenced script on this Behaviour is missing!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
utterly confused
-edit- I also tried to create a new prefab and see if the problems goes away, nope still getting the script two times...
Answer by datorum · Jul 15, 2011 at 10:57 PM
Finally, found the problem. I had the script that instantiates the shot running two times (one JS and C# version, the JS version was still assigned to the 3D Model prefab, whereas in the new version the C# script is assigned to a empty GameObject that instantiates the 3D Model prefab, thus it was a bit hard to find...).
MODS: please close
there's a button under your tags that allows you to close, but you might as well mark this answer as accepted (checkmark by the thumbs) since it's the solution.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144743im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
assign different values to prefabs on instantiation 2 Answers
Control amount of bullets 2 Answers
"Instantiate"/make new function via script? 1 Answer
Instantiate at Location Problem 2 Answers
Scripts of instantiated objects 1 Answer