- Home /
GameObject.transform.Find().position returning local position for instantiated gameobjects.
I'm trying to programmatically instantiate prefabs end to end. Each prefab has its container GameObject at one end, and an empty named "Attachment Point" at the other end, with geometry in between. Here is the code I'm using to do it:
//Instantiate blocks.
GameObject prevBlock = GameObject.FindWithTag("Respawn");
GameObject currentBlock;
foreach(int blockType in blocksToBuild)
{
currentBlock = (GameObject)Resources.Load("LevelBlocks/" + blocks[blockType]);
Instantiate(currentBlock, prevBlock.transform.Find("Attachment Point").position, Quaternion.identity);
prevBlock = currentBlock;
}
When prevBlock is first instantiated, it is assigned a GameObject that already exists in the world. All other assignments to it are prefabs that are generated in the loop.
The issue that I'm running into is that prevBlock.transform.Find("Attachment Point").position is returning the local position of the "Attachment Point" child of each prefab. The very first time it runs, when prevBlock is an existing GameObject, it returns the world position as it should. Every other time, when prevBlock is a programmitcally instantiated prefab, it returns local position.
Your answer
Follow this Question
Related Questions
Changing scale of unit 0 Answers
GameObject moving left to right AND up 1 Answer
How do I instantiate on the game object's position that i put the script on 1 Answer
Instanitiate PreFabs and let them move to different locations 1 Answer
Why can't I get the transform from an instantiated object? 1 Answer