- Home /
Instantiated prefab position
I'm instantiating a prefab multiple times. When I try to get the position of one of these objects, I get the same coordinates for every instance!? Any suggestions?
I'd like to know that, too. I'm trying to trigger cameras in prefab instances. Accessing them via transform.Find doesn't work...
Answer by Jacek_Wesolowski · Mar 01, 2012 at 09:32 PM
You might also want to make sure you're actually creating instances at different positions in space and not some default position (such as the one stored in prefab's transform, or some contant value like the one used in Meltdown's example).
Answer by Meltdown · Mar 01, 2012 at 12:50 PM
Put the instantiated object into a variable...
i.e in C# do something like...
var player = GameObject.Instantiate(playerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
Debug.Log(player.transform.position.ToString());
Answer by frnk · Mar 01, 2012 at 09:32 PM
Thanks for your answer. The solution for my specific problem was something else. The code for the debug output was inside the Update function. I relocated the transform.position part to the OnMouseOver function. Everything works fine now.
Answer by frnk · Mar 01, 2012 at 09:32 PM
Thanks for your answer. After I relocated the transform.position part from Update to OnMouseOver everthing worked fine. Give that a try zerebruin. :)
Answer by Hybris · Mar 01, 2012 at 03:31 PM
It's probably the same problem as look at that object, you first need to confirm that the object is in the scene.
in javascript:
var prefab = GameObject.Find("prefab");
print(prefab.transform.position);
I do not know for sure.