DeviArt
DeviArt

Reputation: 469

Unity3d Transform issues when trying to re-parent a Gameobject with sub-Gameobjects

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

Answers (2)

Engineer
Engineer

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

user2958138
user2958138

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

Related Questions