- Home /
Gameobject spawns at a weird position
Hey. Iam trying to spawn a gameobject as a child of another Gameobject (called Spawnpoint1)
The parent gameobject(Spawnpoint1) is at 15.4 , 0 , 4.9, the prefab is at 0-0-0 and when i spawn the prefab, it appears at -15.4 , 0 , -4.9 (negative values)
the spawn code looks like this:
(Instantiate (SpawnObjects[nav1Position], new Vector3(0, 0, 0), Quaternion.identity) as GameObject).transform.parent = Spawnpoint1.transform;
how can i let it aper at the same position as the parent object? thanks!
Answer by Dibbie · Nov 13, 2015 at 05:32 PM
When you child something to a parent, the child takes its current position (and other settings like rotation and all that), and no longer use the worlds location, it uses the parents location, so the numbers may be different, causing it to move in the world.
You could try using localPosition of that object, or manually setting the values.
Your answer
![](https://koobas.hobune.stream/wayback/20220612044952im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate prefab at certain positions 3 Answers
Spawning objects at random Vector3 3 Answers
I want to respawn the food everytime the snake collides with it 0 Answers
How would i use a 2D array for level generation 0 Answers
Instantiate over time? 1 Answer