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 /
This question was closed Jul 02, 2015 at 10:35 PM by DaiMangouDev for the following reason:

Other

avatar image
0
Question by DaiMangouDev · Apr 12, 2015 at 12:17 PM · c#unity5

OnTriggerEnter will not work in unity 5

  void OnTriggerEnter(Collider other)
     {
         Debug.Log(other);
 
 }

other would be my player which only have a rigidbody and and box collider on it . the object with the trigger set to active is just a simple box with this script on it .

how can i get OnTriggerEnter to work

Comment
Add comment · 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 OctoMan · Jun 19, 2015 at 05:37 PM 0
Share

Both objects need a collider(is trigger) and at least one of them a rigidbody component.

5 Replies

  • Sort: 
avatar image
4

Answer by tanoshimi · Apr 12, 2015 at 01:01 PM

Both objects involved in a collision need to have colliders. So, the "just a simple box" to which this script is attached needs to have a collider component as well.

For OnTriggerEnter to function, the Collider on the object with which the script is attached must be checked "IsTrigger".

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 DaiMangouDev · Apr 12, 2015 at 01:39 PM 0
Share

both of them have colliders. what else could be wrong ?

avatar image SnStarr · Apr 12, 2015 at 02:09 PM 0
Share

I think it is working already its just that you have it debugging out other, which is a collider..Its doing that but not showing you anything..Try (Debug.Log(other.name)

avatar image Basher207 · Apr 13, 2015 at 07:37 PM 0
Share

$$anonymous$$ake sure the other collider is not a trigger, a trigger won't trigger a trigger by default

avatar image tanoshimi · Apr 14, 2015 at 08:14 PM 0
Share

It might help if you could post a screenshot of the inspector panels for the two objects in question - it's a bit hard to follow exactly what setup you have: e.g. it sounds like you have:

Object A (Box): - Box Collider (marked as IsTrigger) - This script

Object B (Player): - Rigidbody (is kinematic?) - Box Collider

If so, can you try attaching this script to the player object, not to the box?

avatar image DaiMangouDev · Jun 19, 2015 at 05:12 PM 0
Share

sorry for the very late reply , I no longer have the project but I will test it out again later on

avatar image
3

Answer by anthodb · Jun 18, 2015 at 04:14 PM

I had same issue and I had to set both of my colliding Gameobjects on the "CollisionLayer". Then it worked ;) I don't know if this is a new feature of Unity5 but I can tell I spent most of the day searching for a solution.. Hope that 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 lightgem12 · Apr 12, 2015 at 05:44 PM

um.. I'm abit new to this so i may be wrong but when you use debug.log you may need quotations. Like

void OnTriggerEnter2D(Collider2D other)//if you are using 3D you dont need the 2D part {

Debug.log ("Hi There"); }

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 meat5000 ♦ · Apr 12, 2015 at 05:45 PM 1
Share

Indeed "" is used to indicate a Literal String (Text).

You can combine items in Debug.Log

 Debug.Log("$$anonymous$$y int value is " + myInt.ToString());

As OP used a variable name the "" are not needed even if that variable is a String.

 String myString = "THIS IS A STRING";
 
 void Update()
 {
      Debug.Log("This is a string and " + myString);
 }


Dont worry, not going to downvote you ;)

avatar image DaiMangouDev · Jun 19, 2015 at 05:10 PM 0
Share

JUST SAYING....I NEVER DOWN VOTE ANYON$$anonymous$$ why do i have to be saying this . Unity needs to show the name of persons who down vote so that we can contact them and ask for their corrections and ideas.

avatar image
0

Answer by meat5000 · Apr 12, 2015 at 05:52 PM

What is this?

 Debug.Log(other);

I'm quite sure you can't output a Collider to the Console.

Did you want

 other.gameObject.name

instead?

Comment
Add comment · Show 7 · 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 DaiMangouDev · Apr 13, 2015 at 12:33 AM 0
Share

if I remember correctly it will output "UnityEngine(Object)". I tried accessing and setting the value of a public variable in a script attached to "other" however no change was made

avatar image meat5000 ♦ · Apr 13, 2015 at 07:34 PM 0
Share

Can you be sure that it functioned as intended? Does that routine work if you uncheck IsTrigger and Use OnCollisionEnter?

avatar image DaiMangouDev · Apr 14, 2015 at 07:29 PM 0
Share

OnCollisionEnter works just fine , but nothing happens once I check isTrigger

avatar image Shark-Boy · Jun 18, 2015 at 11:53 PM 1
Share

Why the down votes?

avatar image DaiMangouDev · Jun 19, 2015 at 05:09 PM 0
Share

JUST SAYING....I NEVER DOWN VOTE ANYON$$anonymous$$

Show more comments
avatar image
-3

Answer by SnStarr · Apr 12, 2015 at 12:49 PM

Use the new Unity UI Event Systems. Include Using.UnityEngine.EventSystems at the top and make sure that your class inherits from IPointerEnterHandler.

Then set up an Event System on the Player and use the following script in your code attached to it.

 void OnPointerEnter(PointerEventData pointerData)
 {
 
 }
Comment
Add comment · Show 7 · 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 DaiMangouDev · Apr 14, 2015 at 07:02 PM 0
Share

Hi, thanks for the help ,however that is not what i am referring to .

avatar image DaiMangouDev · Jun 19, 2015 at 05:09 PM 0
Share

JUST SAYING....I NEVER DOWN VOTE ANYON$$anonymous$$

avatar image bratzka · Jul 28, 2015 at 10:57 PM 0
Share

weirdly i have the same issue. i have a cylinder with a capsule collider and a rigidbody. and a box right in front of it(yes with a box collider and is trigger on). when it passes through neiter onCollisionEnter nor onTriggerEnter goes off. i cant figure out what i have different then the other 300 times that i used this. it feels like a bug.

avatar image bratzka · Jul 28, 2015 at 11:03 PM 0
Share

ok i just opend a fresh project and redid basically this tutorial http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers?playlist=17120 and it doesnt work.

avatar image meat5000 ♦ · Jul 28, 2015 at 11:12 PM 4
Share

Capital O

OnCollisionEnter

avatar image _ahmedfawaz meat5000 ♦ · Jun 08, 2016 at 12:12 PM 0
Share

lol dammit....learning curve ay! thanks for pointing that out

Show more comments

Follow this Question

Answers Answers and Comments

25 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to use the new Dropdown Menu? 2 Answers

Separate Objects after Mouse Clicking in Unity 5.6.4 1 Answer

Manipulating the location of the VR controllers (Vive/SteamVR) in script 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