- Home /
[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
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);
}
Thank you for clarifying that. But the problem stays the same.. Any idea?
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.
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
![](https://koobas.hobune.stream/wayback/20220612153115im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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