Search Unity

collider.enabled?

Discussion in 'Scripting' started by StarManta, Dec 27, 2006.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I can't find a way to disable a collider. Is there one? I'm about to just move the collider to the right 999999 units....

    EDIT: Also, are the script hooks broken? trying to access either collider.bounds or collider.center gives me a MissingFieldException.
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    No, you can't enable/disable a collider. However, you can remove one (just like any other component): Destroy(collider)

    collider.center and collider.bounds: does the game object that the script is attached to actually have the collider? Haven't you accidentally declared your own variable named 'collider' (of different type) somewhere in the script?
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Well, I'd rather not have to rebuild the collider every time I want to enable/disable it.

    As for the second - I'm 90% sure every object this script is on has a collider, and nothing else is named collider. I'll check again later (it's working fine right now with the "moving the transform really far away" approach for now)
     
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Hey StarManta
    You seem to have more answers than I , in general, but what about making the object inactive?
    Code (csharp):
    1.  
    2. var Wall : GameObject;
    3. function Whatever(){
    4. Wall.active = false;
    5. }
    If that messes with other stuff (Like making it inactive stops other behaviours)
    You could duplicate the object in the same space, put some scripts on one(with collider) and other scripts etc on another(and use a trigger?)

    AC
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I could do that, but that would 1) require me to create extra scripts and 2) require me to create extra objects, and 3) would require me to hook them all up.

    It turns out to be mucher simpler to set transform.position to (999999.9,999999.9,999999.9) and then return it when i need it to come back. I posted here hoping for a better solution than that.
     
  6. butterpants

    butterpants

    Joined:
    Aug 29, 2008
    Posts:
    9
    This is really impractical. What happens when you want to turn the collider back on but you've destroyed it?

    I know there's an active state for the component because you can uncheck any component in the editor -- why not just expose that to the script?
     
  7. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    Could you just change the collider to a trigger when you don't want to collide with it?
     
  8. attilam

    attilam

    Joined:
    Jun 2, 2007
    Posts:
    86
    I'm doing this "hack" in a project currently to toggle collision and so far it seems to work fine.