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
2
Question by unitydev0008 · Jan 09, 2011 at 10:19 PM · colliderbugyieldactiveistrigger

Possible Unity BUG? Or am i missing something

Hey guys i recently ran into a problem and kinda stumped on why it acted this way. What happened was i have a gameobject with a box collider attached to it. In this gameobject i have a function to respawn the gameobject when it is killed which simply hides its render and moves it back to its starting position. Now the problem with it was that just hiding the renderer the gameobjects collider would still block incoming projectiles so i added to the respawn code to make the collider.active = false. Now when i did this my respawn code stopped performing its yield statement. Here is the code for reference in C#: float respawnTime = 5f; // How long to wait before respawning

void Start()

{ StartCoroutine(RespawnGameObject()); }

// Function to Respawn the GameObject private IEnumerator RespawnGameObject() { gameObject.collider.active = false; // Deactivate the gameObjects collider gameObject.renderer.enabled = false; // Hide the gameObjects

 Debug.Log("Before the Yield");
 yield return new WaitForSeconds(respawnTime);
 Debug.Log("After the Yield");

 gameObject.collider.active = true; // Reactivate the gameObjects collider
 gameObject.renderer.enabled = true; // Make the gameObjects visible again

}

The above code is what i believe is possibly a bug or am i missing something? The debug statement "Before the Yield" is returned but not the "After the Yield". However with the code below both are returned:

float respawnTime = 5f; // How long to wait before respawning

void Start()

{ StartCoroutine(RespawnGameObject()); }

// Function to Respawn the GameObject private IEnumerator RespawnGameObject() { gameObject.collider.isTrigger= false; // CHANGED TO A TRIGGER gameObject.renderer.enabled = false; // Hide the gameObjects

 Debug.Log("Before the Yield");
 yield return new WaitForSeconds(respawnTime);
 Debug.Log("After the Yield");


 gameObject.collider.isTrigger= true; // CHANGED TO A TRIGGER 
 gameObject.renderer.enabled = true; // Make the gameObjects visible again

}

Now is this a bug or again am i missing something? I dont understand why disabling a collider would effect a yield statement. I have recreated the problem in a seperate project where i add this script to a cube and no other scripts are active and the trigger version works but the active does not. If anyone knows why this is please let me know! Thanks again

Comment
Add comment
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

1 Reply

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

Answer by Mike 3 · Jan 09, 2011 at 10:28 PM

You're setting the GameObject inactive, not the collider (Component.active is a shortcut for setting the GameObject active status).

Since the GameObject is inactive, Unity doesn't call back into the coroutine

It should actually be causing a compilation warning about it being obsolete, along the lines of: the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead.

though that isn't so useful for colliders, which don't have an enabled property

Comment
Add comment · Show 2 · 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 Jesus_Freak · Jan 09, 2011 at 10:36 PM 0
Share

colliders have an isTrigger property, which will cange some things about it, but it is a way to "disable" a collider, at least the colliding part.

avatar image unitydev0008 · Jan 09, 2011 at 10:40 PM 0
Share

thanks for the quick answer mike, i dont recall any warnings but now that u mention it i do remember that being obsolete. Thanks again and now it makes sense!

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

No one has followed this question yet.

Related Questions

Why does isTrigger = true not work without an update? 2 Answers

How do I pass through certain colliders but detect all collisions? 1 Answer

Can i make istrigger true just for spesific object ? 1 Answer

Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers

Is Trigger Collision Problem 1 Answer


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