I have been having an issue with script generated prefabs that use a character controller component. I can generate the prefab in question without any problems. When I try to generate another one, however, all existing prefabs that have been generated all teleport to the location of the newly generated prefab instance. I know it is the character controller component causing the issue because I removed components individually, and this issue doesn’t arise unless the character controller component is active. I would post code, but it really is as simple as having a prefab instance generated at specified location, and then it moving to the location of the next prefab instance once its generated. Side note: if a prefab is dragged into the scene beforehand, and not generated by script during runtime, the issue does not occur. Using just a rigidbody this issue doesn’t arise either. Any advice is greatly appreciated!
You need to be able to individually identify a gameObject. Fortunately this is pretty easy to do…
GameObject go = Instantiate (myPrefab, transform.position, Quaternion.identity) as GameObject;
When you instantiate it assign it to a temporary GameObject variable (I use go above). Now as soon as you instantiate you can either add a script and edit a public variable in that script to identify each object or simply rename each one. Lets say you loop through 10 instantiates with index being the counter from 1 to 10 once you instantiate you can set the name like this
go.name = "Enemy_" + index.ToString();
You should get
Enemy_1
Enemy_2
Enemy_3
and so on, you should also be able to just move the object with
go.transform.position = // your new position.
as go gets overwritten each time you should only set the transform for that newly instantiated object.