Search Unity

bug on order of activation for wheelcolliders

Discussion in 'Scripting' started by creat327, Apr 21, 2011.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I've submitted this already as a bug report:

    There is a bug on the way wheelcolliders are activated/deactivated.

    Create 1 object with a rgidibody, then add a script to it and that script create and add wheelcolliders.
    It works fine.

    Now if you do a gameObject.active=false; on that script...
    you'll get an error saying that the WheelCollider needs a rigidbody to function... yes we know, but we are deactivating the gameobject.
    doing the same with setActiveRecursevily provokes the same error.

    basically, enabling/disabling the tree will throw an error on the wheelcolliders because they seem to get enabled before the rigidbody.

    there is an easy way to solve it for us, I can just do this.gameObject.rigidbody.active=true; even when I disable the tree.
    it will fix it because the rigidbody will be enabled/disabled before the wheelcolliders.

    The problem with this is that rigidbody.active is already deprecated and if removed in any future version, it would not work any longer.
     
  2. Pilot

    Pilot

    Joined:
    Oct 13, 2011
    Posts:
    20
    Thanks for submitting this, i'm having the same problem:

    I have a player and a vehicle, and when I switch from the vehicle back to the player I get a: "WheelCollider requires an attached Rigidbody to function."

    In the fix above did you mean: this.gameObject.rigidbody.active=true; OR gameObject.rigidbody.active=true; ?
    I have tried both, I've put the above both before and after my (gameobject.active = false; ) but I still get the same error.

    Do you know if there are any new developments/work arounds on this? Or should I just ignore the error?
     
    Last edited: Oct 16, 2011
  3. mustafa

    mustafa

    Joined:
    Jun 4, 2012
    Posts:
    24
    Hi, I've run into the same problem but you need to set wheelCollider.enabled = false; Instantiate then wheelCollider.enabled = true