Reputation: 469
I am trying to grab a Gameobject that's placed in the correct spot and re-parent it to different Gameobject transforms using code. I manage to do this by using ..transform.parent = parent.transform but the rotation and position get messed up. How can I keep it's rotation and position when re-parenting?
Thanks!
Upvotes: 0
Views: 1540
Reputation: 8865
Always use gameObject.transform.SetParent(anotherGameObject)
, or you risk exactly the sort of phenomena you've described. See SetParent
docs; there is a second parameter to consider.
The form mentioned in the question still works in many cases, but has been deprecated for a while.
Upvotes: 1
Reputation: 33
Place all game object that you want to parent, to empty game object(example:"EMPTY\PARENT\EMPTY\CHILD") with scale 1:1:1(in editor)or re-scale your parent game object to 1:1:1
Upvotes: 1