Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Atto2O · Oct 30, 2021 at 06:18 PM · collidertriggercrashloadingplaymode

Calling property isTrigger from child gameobject crash Unity on play

If you try to access a collider from your child gameobject and use isTrigger property Unity crash on playmode (infinite loading scene).

         Collider[] collidersObj = gameObject.GetComponentsInChildren<Collider>();
         if (collidersObj == null || collidersObj.Length == 0) { return gameObjectcollider; }
         for (int index = 0; index < collidersObj.Length; index++)
         {
            
             Collider returnCollider = collidersObj[index];
 
             if (returnCollider != null && !returnCollider.isTrigger)
             {
                 // If some child have a colliders not on trigger mode
                 return returnCollider;
             }
         }
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
0
Best Answer

Answer by Atto2O · Oct 30, 2021 at 06:21 PM

I think the problem is on "gameObject.GetComponentsInChildren();" use because it can return a characterController and it misses the property "isTrigger", making unity crash.

         Collider[] collidersObj = gameObject.GetComponentsInChildren<Collider>();
         if (collidersObj == null || collidersObj.Length == 0) { return gameObjectcollider; }
         for (int index = 0; index < collidersObj.Length; index++)
         {
            
             Collider returnCollider = collidersObj[index];
 
             if (returnCollider != null && !ColliderHelper.isTrigger(returnCollider))
             {
                 // If some child have a colliders not on trigger mode
                 return returnCollider;
             }
         }
 
 public class ColliderHelper
 { 
     public static bool isTrigger(Collider colliderObject)
     {
         if (colliderObject == null)
         {
             throw new ArgumentException("colliderObject is null");
         }
         if (colliderObject.GetType() == typeof(SphereCollider))
         {
             return ((SphereCollider)colliderObject).isTrigger;
         }
         else if (colliderObject.GetType() == typeof(BoxCollider))
         {
             return ((BoxCollider)colliderObject).isTrigger;
         }
         else if (colliderObject.GetType() == typeof(CapsuleCollider))
         {
             return ((CapsuleCollider)colliderObject).isTrigger;
         }
         else if (colliderObject.GetType() == typeof(CharacterController))
         {
             return false; 
         }
         
         throw new ArgumentException("collider type is does not exist, name:"+ colliderObject.name);
     }
     
 }
 

Comment
Add comment · Show 4 · 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 Eno-Khaon · Oct 30, 2021 at 06:33 PM 0
Share

I think there's more to it than just this. All of those Collider types (and CharacterController) are derived from Collider, which is the level where isTrigger is at, so they're all just using that as-is.

That said, I'm also not really clear, based on this update, how it was originally supposed to work. What GameObject/Collider was your static "ColliderHelper.isTrigger" supposed to reference originally? It seems more likely that that was the only real problem, and that 4 unique GetType() calls is unnecessary/overkill.

Also, though it's old (2013), this provides some additional feedback/insight on CharacterControllers and isTrigger functionality/compatibility.

avatar image Atto2O Eno-Khaon · Oct 30, 2021 at 06:41 PM 0
Share

Sry that "ColliderHelper.isTrigger" was a typo.

I updated it with: "returnCollider.isTrigger".

I made some more tests: when u use "gameObject.GetComponentsInChildren();" it can return a characterController and it misses the property "isTrigger", making unity crash.

avatar image Atto2O Atto2O · Oct 30, 2021 at 06:55 PM 0
Share

also: https://answers.unity.com/questions/380498/why-a-character-controller-does-not-behave-as-a-tr.html

Show more comments

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

199 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 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 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 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 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 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 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 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 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 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 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 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

Can't click gameobject when over another trigger? 1 Answer

How to do Multiple OnTriggerEnters 2 Answers

How to check if a BoxCollider is hit by a trigger? 1 Answer

How to add colliders to an array, and pick the oldest one? 1 Answer

Check if trigger is occupied 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