Scripted GameObject falls through floor after transform.localscale

Hi all,

I’ve searched the forums and Google for help regarding this issue, but I haven’t managed to find a solution yet.

In Unity, I have been generating gameObjects (almost) entirely from script (meshes, joints, and colliders included), and it all has been working fairly well, but I’ve ran into a problem when I attempt to use transform.localscale on my gameObject. All of it re-sizes as expected, but the gameObject will no longer collide with terrain or a plane. Instead, it now falls right through.

All objects generated via script are sub-components of the gameObject that my script is attached to (hence “almost” entirely generated form script). My gameObject has been defined with original specifications in centimeters, but since Unity’s default unit of measurement seems to be meters, my gameObject ends up being the size of a building. I am attempting to transform.localscale the entire object to remedy this situation.

None of the colliders are marked as trigger, all colliders are convex, and none of the colliders seem to be touching other objects when they spawn. Oddly enough, when I highlight my gameObject in Edit mode, all of the colliders are the correct size, and in the correct positions.

Based on what I have learned so far, I think that it might be an issue regarding the raycasts of the colliders not being updated when the colliders are resized (assuming my understanding of colliders is accurate). What do you guys think? Is there any way that I can “refresh” the physics of the colliders at runtime? Is there anything else I could to resize my gameObject and all of its children? I have tried changing their options and translating them in an attempt to force Unity to do so, but I have still had no luck. I should also note that I use mesh and wheel colliders at the moment.

Could it be that the colliders on the gameObject are colliding with other colliders on the gameObject when they are transform.localscaled, thus causing the gameObject to fall through the terrain? I know that kind of thing is a common issue, but the the gameObject is nowhere near the terrain when it is created (or scaled), so the colliders should still collide with the terrain correct?

I found the problem.

Oddly enough, it was a frame update problem. After my gameObject was scaled, it ended up very far above the ground, and so far, in fact, that as it fell through the terrain, Unity did not have enough time to register a collision. In other words, in one frame, it was completely above the terrain, but in the next, it was already below the terrain (so there was no frame in which the gameObject and the terrain were actually intersecting). The solution was to move the gameObject closer to the ground so that it would not acquire so much speed (thus, allowing Unity to register the collision).