Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
2
Question by Hellfish · Dec 21, 2010 at 07:13 PM · triggerontriggerenter

OnTriggerEnter only works if gameObject is moving

Hi,

I have a question regarding the onTriggerEnter function. My scene has the following set up:

I have one gameObject with a rigidbody component and is Kinematic set to true. This object can be controlled by the player and should avoid upcoming obstacles, without beeing affected by the physics system.

The obstacles have a box collider and isTrigger set true.

the player object has the following script running:

function OnTriggerEnter(myTrigger : Collider){

Debug.Log(myTrigger.gameObject.name)}

My problem is that the onTriggerEnter function is only called when I move the player object, while it hits the trigger. If it is standing still while the trigger hits it, the function is not called. Is there a failure with the script or the set up? Because I need to activate the trigger, even if the player object is not moving.

Thanks in advance

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

5 Replies

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

Answer by Ejlersen · Dec 21, 2010 at 07:59 PM

Just looked through the documentation. Maybe you can find your answer here:

BoxCollider and triggers

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 Hellfish · Dec 21, 2010 at 08:22 PM 0
Share

Hi, I already the chapter over and over and it seems like I# m missing something. $$anonymous$$aybe rigidbodys need to be in movement to make trigger checks but that wouldn't make much sense, would it?

avatar image Ejlersen · Dec 21, 2010 at 08:26 PM 2
Share

Triggers are most often used as something staticly in the scene, which is then triggered by something moving into its collider. Rarely its the other way around. You could try to add a rigidbody to the trigger object, maybe then it will register.

avatar image Hellfish · Dec 21, 2010 at 08:37 PM 0
Share

Thanks a lot. I added a rigidbody and put set it to kinematic and now it works.

avatar image
8

Answer by jordankid93 · Jan 01, 2019 at 07:07 AM

Incase others might come across this, I was having an issue where a collider2d that I toggle activate wasn't triggering OnTriggerEnter2D until I moved. The solution for me was that I had to set my RigidBody2D sleeping mode to Never Sleep.

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 Tyrant7 · Sep 10, 2019 at 01:59 AM 0
Share

This worked very well, thanks!

avatar image
2

Answer by Buzzrick · Aug 02, 2013 at 02:02 AM

I had exactly the same problem. It took a bit of figuring out but the documentation on BoxCollider states that:

"If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving."

I ended up having to add a Rigid body to both of my objects for this to work consistently, because they were both moving objects.

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

Answer by Occma · May 12, 2015 at 09:44 AM

I have the same Problem and as I see, this is one of the first threads to pop up in google.

To fix the bug in my case a added the rigidbody to the moving object instead of the player. Now both have rigidbodys and behave as intended.

Hope this helps

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

Answer by ycode · Dec 27, 2018 at 05:39 PM

I still got the same symptom although my gameobjects already had Rigidbody, as other answers mentioned.

Then, I found that even having Rigidbody, onTriggerEnter is still not called if the both gameobjects' rigidbodys do not have "Use Gravity" checked.

Checking "Use Gravity" of Rigidbody on either gameobject makes onTriggerEnter called without the gameobjects moving.

It's been a while since the question is raised, so that I'm not sure it was the case back then, but at least, it works this way as of Unity 2018.2.18f1.

btw, this is also the same for OnCollisionEnter.

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

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

6 People are following this question.

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

Related Questions

OnTriggerEnter gives me error? 2 Answers

Disable Mesh Collider Trigger 1 Answer

OnTriggerEnter fails to activate 1 Answer

OnTriggerEnter only sent to one of the colliding objects, not both? 0 Answers

low impact alternitve to onTriggerEnter 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