[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

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);
    }