Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by usagijojo · Aug 18, 2013 at 09:19 AM · collidercollidersdisabling

Disabling colliders not actually working

So I'm working on a beat-em-up type of action game where players can pick up boxes and throw them. However, I noticed that when a box was lifted over a character's head, the box collider on the objects would actually stop a player from jumping (they would "hit their head" on the box and come right back down). So of course, I decided to disable all colliders on the object so that this wouldn't happen, and instead extend the player's own collider up to compensate.

Here was the relevant code:

     class BaseItem extends MonoBehaviour
     {
             function PickedUp(parentTransform : Transform){
                 //For the box collider
                 this.collider.enabled = false;
     
                 //This item also has a trigger collider
                 var triggerCollider : CapsuleCollider = this.GetComponent(CapsuleCollider);        
                 triggerCollider.enabled = false;
             }
     }

However, this was when I was experimenting with all my code inside of the BaseItem class.

When I decided to make a separate ThrowableItem class, I moved this code into the overridden version of the function:

     class ThrowableItem extends BaseItem
 {
        override function PickedUp(parentTransform : Transform){
             //For the box collider
             this.collider.enabled = false;

             //This item also has a trigger collider
             var triggerCollider : CapsuleCollider = this.GetComponent(CapsuleCollider);
             triggerCollider.enabled = false;
     
         }
 }

Now, for whatever reason, the colliders aren't disabling... Even though the Unity editor says that they are disabled. That's right... The Unity editor claims that the colliders have been turned off, even though the game still registers them being there.

I can even delete the colliders entirely off of the item mid-game and they will still register as being there. How is that possible? If they're deleted, why are they still there?

I'm supposing this might have something to do with ThrowableItem being a child of BaseItem, but I can't figure out why it happens this way and how to change it.

Any help is greatly appreciated!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image usagijojo · Aug 18, 2013 at 10:13 AM 0
Share

Wait, what's this? I just realized that the object has a new SphereCollider inside of the box that came out of nowhere!

And even stranger, it's not listed under the object's components, either!

Have I come across a bug in Unity...?

avatar image usagijojo · Aug 18, 2013 at 10:30 AM 0
Share

I can't access the mysterious new collider through scripting, either... What on earth happened, I wonder?

avatar image Linus · Aug 18, 2013 at 10:32 AM 0
Share

An image of the inspector settings and scene would help

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by usagijojo · Aug 18, 2013 at 10:40 AM

Ahhh, I figured out my problem!

I accidentally added this to my BaseItem code:

 @script RequireComponent(CharacterController)

Copied over from the BasePlayer class. Whoops! Sorry for troubling you guys.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Aug 19, 2013 at 07:06 AM 0
Share

Glad you found it. I've converted your comment to an answer.

avatar image
0

Answer by whydoidoit · Aug 18, 2013 at 09:21 AM

If you are going to move or change colliders then the associated object needs to have a rigidbody to keep the physics system up to date. This rigidbody can be set to isKinematic = true to avoid it actually doing physics calculations.

Basically colliders are not expected to move or disappear if they aren't attached to some kind of rigidbody.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Aug 18, 2013 at 09:22 AM 0
Share

Though that really doesn't explain why it ever worked of course!

avatar image usagijojo · Aug 18, 2013 at 10:09 AM 0
Share

I added Rigidbody, and set is$$anonymous$$inematic = true... But it didn't change anything.

$$anonymous$$eep in $$anonymous$$d that even deleting the colliders manually doesn't seem to do anything, either.

avatar image whydoidoit · Aug 19, 2013 at 07:05 AM 0
Share

Yep, but just for reference it's necessary to do that to avoid weirdness and performance penalties. Obviously something else as we'll in this case.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A script that auto generated the box collider around a 3d model 3 Answers

How can I change animation with colliders? Using AR and Vuforia. 0 Answers

OnCollisionEnter2D is not working 0 Answers

raycasts only working with IsTrigger colliders? 1 Answer

detect if collider is not touching anything 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges