• 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
Question by chase cobb · Nov 01, 2013 at 02:50 AM · rigidbodytriggeroncollisionenter

Trigger and collision events not being called

I have two objects that I would like to know when they collide. As a disclaimer I have read the documentation several times and am currently following what is says precisely, or so I think. Inspector views of the objects are included below.

The object I'm checking the collision against is a cube with a non-kinematic rigidbody and a box collider. The other object is a plane with a box collider, that is marked as a static object. Both are on the Default physics layer. OnCollisionEnter and OnTriggerEnter are both not being called, not matter if the plane is marked as a trigger or not.

Here are both scripts:

cube

 using UnityEngine;
 using System.Collections;
 
 public class BoxScript : MonoBehaviour {
 
     public enum BoxTypes
     {
         BOX_1X1,
         BOX_1X2,
         BOX_1X4
     }
     public enum BoxColor
     {
         BLUE,
         GREEN,
         RED,
         YELLOW,
         ORANGE,
         WHITE
     }
     
     /*****************************************
      * Public Variables*/
     public BoxTypes m_boxType = BoxTypes.BOX_1X1;
     
     
     /*****************************************
      * Private Variables*/
     private bool m_isSelected;
     private BoxColor m_color;
     
     /// <summary>
     /// Property for setting/getting selected boolean
     /// </summary>
     public bool IsSelected
     {
         get
         {
             return m_isSelected;
         }
         set 
         {
             m_isSelected = value;
         }
     }
 
     /// <summary>
     /// Initialization
     /// </summary>
     void Start () 
     {
         m_isSelected = false;
 
         m_color = DetermineColorByMaterial();
     }
 
     public BoxColor GetColor()
     {
         return m_color;
     }
 
     private BoxColor DetermineColorByMaterial()
     {
         string materialName = renderer.material.name;
 
         char[] delims = {'_'};
 
         string[] colorNames = materialName.Split(delims);
 
         if (colorNames.Length > 1)
         {
             string color = colorNames[colorNames.Length - 1];
 
             if (color == "Blue")
             {
                 return BoxColor.BLUE;
             }
             else if(color == "Green")
             {
                 return BoxColor.GREEN;
             }
             else if (color == "White")
             {
                 return BoxColor.WHITE;
             }
             else if (color == "GOLD")
             {
                 return BoxColor.YELLOW;
             }
         }
 
         return BoxColor.ORANGE;
     }
 
     void OnTriggerEnter(Collider collider)
     {
         Debug.Log("trigger hit!");
     }
 
     void OnCollisionEnter(Collision collision)
     {
         Debug.Log("Collision happened on box!");
     }
 }


plane

 using UnityEngine;
 using System.Collections;
 
 public delegate void CollisionDetectedEventHandler(BoxScript.BoxColor boxColor);
 public class SwitchTarget : MonoBehaviour 
 {
     public CollisionDetectedEventHandler OnCollisionWithBlock;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter(Collider collider)
     {
         Debug.Log("Trigger has been entered");
     }
 
     void OnCollisionEnter(Collision collision)
     {
         Debug.Log("Collision happened!");
         //did we collide with a box?
         if (collision.gameObject.GetComponent<BoxScript>() != null)
         {
             //now get the color of the box
             if (OnCollisionWithBlock != null)
             {
                 OnCollisionWithBlock(collision.gameObject.GetComponent<BoxScript>().GetColor());
             }
         }
     }
 }
 

The test case I am using is the cube falling onto the plane when the scene starts. I'm wondering if for some reason the rigidbody on the cube is sleeping, but as soon as it hits the plane it should wake up.

alt text alt text

cube.png (51.4 kB)
plane.png (37.0 kB)
Comment

People who like this

0 Show 2
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 chase cobb · Nov 01, 2013 at 07:02 PM 0
Share

A simple package with the problem has been included. Any help would be greatly appreciated.

Example Collision Problem Project

collision_testing.zip (195.0 kB)
avatar image sdgd chase cobb · Nov 01, 2013 at 07:27 PM 0
Share

Please don't post answer as a comment or additional info

1 Reply

  • Sort: 
avatar image

Answer by Programmer-Tau · Nov 02, 2013 at 04:22 AM

alt text

I just tried your package. OnCollisionEntered is being called. So... it works on my machine.


screen shot 2013-11-01 at 21.14.25.png (127.9 kB)
Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

OnCollisionEnter without disabling isKinetic 1 Answer

Access other collider without use of Trigger collider. 1 Answer

On Trigger Enter, Collide with object, specific collision 1 Answer

OnCollisionEnter called twice 2 Answers

How do i destroy only 1 object when 2 instances of the same object collide ? 2 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