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
0
Question by fluxhackspro · Feb 21, 2018 at 04:21 PM · scaleparent

[SOLVED] Set parent glitches the object and changes its scale?

Hello

So im simply shooting arrows and when it's hitting a collider it's rigidbody is set to kinematic and it's parent is the Colliders transform.

But The arrows glitch out dramatlicly and it's scale changes somewhat random and is flatten out on the ground. Note it also spams the log with i quote:

"BoxColliders does not support negative scale or size, The effective box size has been forced positive and is likley to give unexpected collision geometry"

Why is it changing the scale of the arrow? I know the boxcollider is scaled with the arrow so that explains the error but why does the arrow object scale like crazy just from these two lines of code:

 void OnTriggerEnter(Collider col)
     {
         GetComponent<Rigidbody> ().isKinematic = true;
         transform.parent = col.transform;
     }


Thanks ~Flux

[EDIT] Thanks to @Harinezumi i learned that transform.parent is not longer used and that SetParent is a better way of doing it. Altough setting the worldpos to true did not work for me so i set it to false.

Thanks @Harinezumi

Comment
Add comment
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

1 Reply

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

Answer by Harinezumi · Feb 21, 2018 at 04:30 PM

Setting transform.parent directly has been deprecated sometime in Unity 5, you should instead use transform.SetParent(Transform newParent, bool worldPositionStays = false);. This second parameter is the key to the weird behaviour you see: by default it is false, which means that SetParent() will recalculate the newly parented child's whole transform in the local space of the new parent, including scale.
To avoid this (which you almost always want), you need to explicitly supply true as the second parameter to SetParent(), in your case:

 void OnTriggerEnter(Collider col)
     {
         GetComponent<Rigidbody> ().isKinematic = true;
         transform.SetParent(col.transform, true);
     }
Comment
Add comment · Show 3 · 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 fluxhackspro · Feb 21, 2018 at 04:46 PM 0
Share

Thank you for clarifying that. But the problem stays the same.. Any idea?

avatar image Harinezumi fluxhackspro · Feb 21, 2018 at 06:00 PM 0
Share

You are welcome... but I'm confused... did setting it to false work?
Please don't accept the answer if it did not solve the issue.

avatar image simpleyuji · Apr 14, 2021 at 10:42 AM 1
Share

In my case, I have to supply false in transform.SetParent(col.transform, false) to make it not have its scale changed to a very large number. Setting it to true as per the recommended answer didnt work (probably a typo?)

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

77 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

Related Questions

Scale a prefab without reference to parent 1 Answer

Rotating an object within its parent's scale 0 Answers

Make a simple tree 1 Answer

Moving Platforms & Scale (Parent/Child) 1 Answer

Object scale/rotation changes when parented to flipped 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