• 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 /
This question was closed May 29, 2016 at 10:48 PM by Le-Pampelmuse for the following reason:

The question is answered, right answer was accepted

avatar image
5
Question by 432qwerty · Jul 21, 2014 at 05:39 PM · collisiongameobjectrigidbodyontriggerenter

OnTriggerEnter not working, tried everything! :( (C#)

Hi, I've only spent a week using Unity so far so very new! Trying to make an arcade-style falling game within a tunnel. I can't get this to work, despite having used this before successfully.

 void OnTriggerEnter(Collider other)
     {
         print("YAY!");
         if(other.gameObject.tag == "Finish" && finished == false){
             
             if(terminal == true){
                 win_text.text = "YOU WIN!";
             } else {
                 lose_text.text = "YOU LOSE...";
             }
             finished = true;
         } else if (other.gameObject.tag == "Obstacle"){
             // can add response to collision with obstacles.
         }
     }

To my disappointment, the phrase "YAY!" is never printed, and there is no interaction with the various GUIText elements.

As you can see, I tried fixing it by having the GUIText not constantly refresh (it finishes with constant contact) by adding an extra boolean, but it wasn't even being run in the first place.

The player (sphere, Sphere Collider) has this script attached to it, and the finish (cube, Box Collider) has the tag "Finish". The player has a Rigidbody, the finish doesn't.

I've been stuck on this for hours now and looking at similar posts I can't resolve the problem. Please help!

Comment
Comments Locked · Show 1
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 tanoshimi · Jul 21, 2014 at 06:16 PM 0
Share

And the finish box collider is marked as trigger?

3 Replies

  • Sort: 
avatar image
70

Answer by OLP · Jul 21, 2014 at 06:48 PM

For your objects to receive the OnTriggerEnter, at least one of them has to have the Is Trigger property checked and at least one of them has to have a Rigid Body. If neither of your objects is a Trigger, you can use OnCollisionEnter instead.

Once that's all set, you should check the Layers (not Tags) on your objects. To edit which Layers collide with each other, you can look at Edit -> Project Settings -> Physics.

By default Unity sets all layers to collide with all layers. That's a good works-by-default setup, but you may want to play with it to optimize later on.

Comment
Add comment · Show 5 · 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 $$anonymous$$ · Jul 21, 2014 at 09:19 PM 0
Share

You should probably search for the collision table.I think you can see it on the BoxCollider manual page.There it says what kinds of colliders can successfully collide with others.That means kinematic,static,rigidbody,triggers whatever.It will be incredibly helpful down the road.

avatar image KarlKarl2000 · Aug 26, 2016 at 06:32 PM 5
Share

@OLP

Totally forgot about adding the RigidBody. Thanks for the re$$anonymous$$der :)

This also nicely works in combination with OnTriggerEnter2D (Collider2D other) .. and again you need to have the RigidBody2D + box collider2D (with is trigger) added to the gameobject too.

avatar image $$anonymous$$ KarlKarl2000 · Mar 02, 2017 at 08:21 PM 2
Share

i've been stuck on this for a while and only just noticed that I had to use OnTriggerEnter2D vs OnTriggerEnter, other's having trouble that just can't seem to figure it out make sure you are using the right function call if you are in 2D

avatar image cm_2303 · Jun 29, 2020 at 08:09 PM 0
Share

Still not working for me

avatar image tennorlee · Mar 14, 2021 at 09:39 AM 0
Share

other than all mentioned above (rigidbody, isTrigger), both objects should have colliders assigned to them as well.

avatar image
0

Answer by 432qwerty · Jul 21, 2014 at 08:10 PM

Thanks for the response, it's really helped me understand this better, but I found the issue... I was using the wrong function! I should have used onCollisionEnter all along, but thanks for the advice!

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 Firedan1176 · Jul 30, 2015 at 03:01 PM 10
Share

This isn't the answer, please select the correct answer and revert this to a comment.

avatar image
0

Answer by manzyron · May 26, 2016 at 09:48 PM

Hi in 5.3.4 both objects need to have rigid body

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 Le-Pampelmuse · May 26, 2016 at 09:52 PM 4
Share

That's wrong. Only one needs a rigidbody. Check twice before you write an answer.

avatar image Lukey_BlueNose · Jul 11, 2017 at 03:53 AM 0
Share

this awnser helped me :) thanks... either one or the other needs a rigid body... was scratching my head for a while over this haha

avatar image NicBird · Mar 04, 2021 at 02:40 AM 0
Share

It is true. I have a rigidbody2d on my zombie object and no rigidbody2d on my arrow object. Arrow doesn't detect any ontrigger2d collisions until rigidbody2d to it is assigned

avatar image logicandchaos NicBird · Mar 04, 2021 at 04:37 AM 0
Share

then there must be some other issue in your project because of a collision only one object needs a rigidbody.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

How do I stop a timer with OnTriggerEnter()? 0 Answers

Waypoint Question(Conflicting Collision) 1 Answer

Collision Checking 1 Answer

Transform collider not detecting collision on rigidbody collider 2 Answers

OnTriggerEnter not firing if rigidbody is on its side 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