Search Unity

How to duplicate setparent behavior effect on scale from Inspector/Editor in code

Discussion in 'Editor & General Support' started by aggamer, May 25, 2016.

  1. aggamer


    Apr 8, 2013
    I want an object to retain its scale/position/rotation when parenting in code the same way it does in the editor when dragging and dropping an object into another object in scene hierarchy, parenting it. I thought using the bool parameter in setparent would work but it still skews things and I can't figure out the combination of localscale/position/rotation adjustments to duplicate what the editor does when moving objects around the hierarchy in the scene.

    voidOnCollisionEnter(Collision collider)
    transform.SetParent(collider.transform, false);

    This does not seem to accomplish the same thing that happens for me in editor when dragging an object already in scene under another object.