Instantiated prefab position (37477)

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?

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).

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());

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.

Thanks for your answer. After I relocated the transform.position part from Update to OnMouseOver everthing worked fine. Give that a try zerebruin. :slight_smile:

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.