paranteing game object at run time

Hi All,

I have this weird thing. I have Transform a and Transform b. In trigger Event I parent transform b to a (b.parent = a). After parenting the location of the parent (that is Transform a) is changed from its original position. Transform a (the parent) is an empty game object attached to no one.

Any ideas?

Thank u in advance

Are you looking at transform.localPosition or transform.position (i.e., global)? When you parent, localPosition will be changed relative to the new parent.

From: Unity - Scripting API: Transform.parent

Changing the parent will modify the parent-relative position, scale and rotation but keep the world space position, rotation and scale the same.