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
1
Question by ttzilla · Apr 18, 2012 at 02:43 PM · collisionontriggerenterdetectioninfinite

OnTriggerEnter detects collision constantly after GO enters the box.

Hi,

I looked for a similar post but couldn't find any other problem like this. So here's another collision issue for you...

Situation:

I have a Box Collider that is a Trigger & a Rigidbody that is Kinematic attached to an object called "objA". (objA is attached to the camera.)

I also have another object with a Sphere Collider that is NOT a trigger and a rigidbody that is NOT Kinematic attached to, which I call "Pizza".

objA is very big and can encapsulate Pizza on collision. I added a print statement that prints the name of the collifing object on OnTriggerEnter and attached this to objA. (It prints many other objects' names on enter once the objects enters. That's working fine.)

My problem is:

However, when Pizza enters objA, the OnTriggerEnter event detects Pizza without stopping! Pizza is the only one that gets read countless times eventhough it never leaves the box after entering. So it enters the objA and stays there and I can see the print statement go crazy, running constantly!

How do I solve this problem? Why does this happen?

Thanks!

Comment
Add comment · 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 bodec · Apr 18, 2012 at 02:45 PM 0
Share

Could you post your code so we can see it please.

avatar image ttzilla · Apr 19, 2012 at 08:20 AM 0
Share

When I removed the Rigidbody from Pizza it starts acting normally. Appearing once in OnTriggerEnter. However I need the rigidbody on this object. There is not much code to show. There's only:

void OnTriggerEnter (Collider other) { print ("ENTER = name is " + other.gameObject.name); }

4 Replies

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

Answer by ttzilla · Apr 19, 2012 at 03:19 PM

I found the answer to my question and that was this line:

other.gameObject.SetActiveRecursively(true);

that I executed OnTriggerEnter. I'm guessing I was reactivating an object recurdively and upon REreactivation it enters the trigger again which causes an infinite loop.

Thanks for your time!

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 burhanasikwala · Nov 01, 2020 at 10:33 AM 0
Share

Hey can you please give an example cause I am too confused about this

avatar image
7

Answer by ddf · Apr 23, 2015 at 09:09 PM

This can also happen if you have a CharacterController inside of a Trigger and are setting the CharacterController's radius every frame.

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 cubrman · Sep 30, 2016 at 07:38 AM 0
Share

Details like this... Priceless! Ty man!

avatar image Ali-Nagori · Apr 16, 2018 at 01:10 PM 0
Share

First of all, i really thank you for this information, very helpful. and second, updating any value not just the radius of the CC will cause this

avatar image
0

Answer by fafase · Apr 19, 2012 at 08:34 AM

Could it be that you are misusing the collision functions.

OnTriggerEnter(other:Collider) means you don't want the physics engine to interact. So the 2 objects will simply pass each other through, still you can make things happen.

Try using OnCollisionEnter(other:Collision) if you want to object to collide and bounce without passing through.

Now, you need to decide what you want to happen,do you want object to get through it or not. Do you only want the pizza to bounce? Your objA is trigger so the physics engine is off, IsKinematic also disables the rigidbody collider. Meaning you have there a zone more than an object. The console prints because it reports a collision on every frame, now you would have to define some more behaviours once the collision happens.

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 ttzilla · Apr 19, 2012 at 08:47 AM 0
Share

What I want is them to overlap without bouncing, However, I want the Pizza to bounce against other objects in the game with rigidbodies and colliders. In other words I want ObjA to be the transparent/permeable screen that takes things in and out without bumping anything, while Pizza bumps at objects like him. I've tried OnCollisionEnter, but I will try again and report back.

avatar image ttzilla · Apr 19, 2012 at 08:53 AM 0
Share

When I use OnCollisionEnter it only detects when I bump into objects and push them around physically.

avatar image fafase · Apr 19, 2012 at 10:01 AM 0
Share

You might want to try and ignore collision http://unity3d.com/support/documentation/ScriptReference/Physics.IgnoreCollision.html

avatar image
0

Answer by nathanvog · Oct 23, 2019 at 05:34 PM

It also seems to happen if your collider vertices are edited on every frame (by a Deformer for example).

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

11 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

Related Questions

Best practice for OnTriggerEnter detection 1 Answer

Detect when a trigger has entered a collider 1 Answer

how do i correctly use a box collider 1 Answer

OnTrigger functions only work when in motion? 1 Answer

how do i correctly use a box collider 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