Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by bioinfbloke · Sep 12, 2018 at 10:18 PM · childparentingworldspacelocalspacewarp

setting parent as object warps the child object

I have two cubes, cube1 and cube2. Both cubes are the same size initially.

cube1's transform Rotation is 0,45,0 and Scale is 1,1,0.3.

cube2's transform Rotation is 0,0,0 and Scale is 1,1,1.

If I make cube2 cube1's child, cube2 warps (see image). I want cube2 to move with cube1 but not be warped. This doesn't happen if cube1's Scale is 1,1,1. How do I stop cube2 warping? I actually dynamically parent cube1 in code so would be happy with a code based solution.

After parenting: After

Before Parenting: before Thanks for any help!

cube1cube2.png (38.1 kB)
cubesbefore.png (21.8 kB)
Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nikola7007 · Sep 12, 2018 at 10:24 PM 0
Share

Have you tried transform.localScale = Vector3.one; to reset the scale back to 1,1,1 after setting the parent?

avatar image tormentoarmagedoom · Sep 12, 2018 at 10:38 PM 0
Share

Good day.

Then i see i was wrong...

So on solution can be after parinting it, change its local scale again.

avatar image Hellium tormentoarmagedoom · Sep 13, 2018 at 05:02 AM 0
Share

As pointed out by the OP the problem can occur when the scale of the parent object is not uniform. Try it by yourself.

avatar image tormentoarmagedoom Hellium · Sep 13, 2018 at 07:40 AM 0
Share

Hello Hellium, But if you have 2 objects with dirrefent scales and make one child of the other, you will see in the inspector that local positions, scale and rotation will change, But its global posit, rot and scale should not change... Parenting and unparenting does not change the "appearence" of the objects..? I'm not right? I can not try it until this night so... to prevent cofusions if is not tre , my answers should be removed.

Thx Hellium!

Show more comments
avatar image Hellium · Sep 13, 2018 at 07:00 AM 1
Share

I don't know if the following suggestion will be possible for you:

I would create a new empty gameObject, and parent both cubes to it. Then, move the empty gameObject ins$$anonymous$$d of the cube1.

avatar image bioinfbloke Hellium · Sep 13, 2018 at 11:26 AM 0
Share

same comment as @vrjeans. Good answer!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by vrjeans · Sep 13, 2018 at 08:43 AM

Hello
I've encountered this problem also. This happens because child gameobjects inherit all of their parents' scales and rotations. The simple solution is to just place both your gameobjects under an empty parent gameobject with the rotation (0, 0 ,0) and scale of (1, 1, 1) and then rotate and scale them individually. To make your cube2 follow cube1 you will have to move the empty parent gameobject and both your cubes will follow. Rotating the parent should rotate all children (they will all rotate around a common pivot point, as if they were all one object) but scaling the parent will result in weird warps as you already noticed.
As for a code solution:

var prarent = Instantiate(parentPrefab); // an empty gameobject prefab with nothing except a transform
var cube1 = Instatiate(cubePrefab); // your cube prefab
var cube2 = Instatiate(cubePrefab);
cube1.transform.parent = parent.transform;
cube2.transform.parent = parent.transform;
cube1.transform.rotation = Quaternion.Euler(0, 45, 0);
cube2.transform.rotation = Quaternion.Euler(0, 0, 0);
cube1.transform.localScale = new Vector3(1, 1, 0.3);
cube2.transform.localScale = new Vector3(1, 1, 1);

something like that. You could probably use one of the Instatiate overloads to make it nicer looking.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bioinfbloke · Sep 13, 2018 at 11:00 AM 0
Share

Thank you so much. I had been stuck on this for a couple of days! Parenting both to an 1,1,1 scaled empty works. Incidentally, I can also scale the empty (uniformly) and that works to scale both children.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

91 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Specific use of TransformDirection 0 Answers

Make a simple tree 1 Answer

What is the difference between TransformDirection, TransformVector and TransformPoint since they all accept and return a Vector3 value. 1 Answer

[Solved] Animation destroying along with the GameObject its a child of 1 Answer

Very Erratic behavior when parenting an object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges