WheelCollider requires an attached Rigidbody to function.

Hi

I have a car GameObject with RigidBody component and children with WheelColliders my hierarchy looks like this:

  • Car (RigidBody)
    • Mesh

      Body (Mesh Renderer, Mesh Filter, Box Collider)

      Wheel_1 (Mesh Renderer, Mesh Filter)

      Wheel_2 (Mesh Renderer, Mesh Filter)

      Wheel_3 (Mesh Renderer, Mesh Filter)

      Wheel_4 (Mesh Renderer, Mesh Filter)

    • Wheels

      Wheel_1 (WheelCollider)

      Wheel_2 (WheelCollider)

      Wheel_3 (WheelCollider)

      Wheel_4 (WheelCollider)

When the scene is loaded the wheels give the following error:

“WheelCollider requires an attached Rigidbody to function.”

However they work as they should. How can I eliminate this error message?

Your hierarchy is correct. That problem surely comes from some script trying to configure functions at the WheelColliders prior to the rigidbody to be initialized.

Try setting up an empty scene containing a car with same hierarchy and no scripts at all. There should be no error here. Add your scripts one by one until you receive the error. Then try commenting out portions of the offending script until you find the exact code that causes the problem.

It's asking for a Rigidbody on the WheelCollider (Being the Wheel_1---4), so on those, add a Rigidbody under the components>physics tab up top...

And you could always take out the code where it says it requires it...

Following should solve ur problem
suppose goCar is gameobject referring to Car (root of ur hierarchy), then while activating/re-activating the gameobject do this:

goCar.active = true;
goCar.SetActiveRecursively(true); // now wheel colliders will be able to find rigidbody since it has been made available in previous line

First line ensures that the rigidbody is already activated for the children activated by the second line.