- Home /
Parenting an object changes its transform.
Hello, i am having a problem with parenting. After i set my scene, write my scripts and done with everything, i want to parent the objects in my scene and put it as a prefab. Before this everything works normal but after doing this position of my objects turn crazy and when i instantiate a prefab through a script that is attached to one of the objects in the scene, it just instantiates the prefab into parents position instead of the position of that object. this probably has something to do with relative position of objects to the parent but something doesn't add up. I can just remove the parent and be done with this but i'd like to understand why this happens and how to avoid it.
The code for the instantiating object(instantiated by an object in the scene which is active and always there);
public GameObject kücükÇember;
public static bool kontrol2;
float zaman=0;
void Start()
{
kontrol2 = true;
}
void Update()
{
if (Input.GetButton("Fire1")&&(Time.time>zaman)&&(kontrol2))
{
zaman=Time.time+0.2f;
cemberOlustur();
}
}
GameObject cemberOlustur()
{
return Instantiate(kücükÇember, transform.position, transform.rotation);
}
}
Pozition for object the instantiator script is attached to; before: (-0.0199 , -1.8899, 0,0677 ) after: (-56.432, -100.15, 5.0677) and parents location: (56.4127, 98.2671, -5)
The instantiated object just spawns where the parent is.
1) How are you parenting the objects? In the Editor or via script?
2) Can you show the code for instantiating your prefab and tell me what object it's attached to?
3) Can you give an example of the world position of the child before and after parenting?
1) I do it via Unity not script. For the rest i updated the question.