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
0
Question by ChrisHorrigan · Jun 11, 2015 at 10:38 AM · colliders

I copied my project from Unity 4 to Unity 5. OnTriggerStay is no longer working -- what changed?

As the title says, I switched from Unity 4 to Unity 5. Everything works except for one thing: I have an OnTriggerStay function that is no longer called when my capsule collider enters a sphere collider. I have the project open in two windows: one is Unity 4, and it works, and one is Unity 5 and it doesn't work. So I'm assuming the way you would handle that type of stuff has changed. Can someone fill me in? Let me know if you need more info.

Update: changing the function from OnTriggerStay to OnTriggerEnter makes it get called. Unfortunately, I need OnTriggerStay, which seems to have been messed with. Can't find anything about it in the release notes. I'm on 5.1

Comment
Add comment · Show 12
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 Owen-Reynolds · Jun 11, 2015 at 04:43 PM 0
Share

$$anonymous$$y guess would be it is being called, but some code inside is working differently. You've got Debug.Log("got here"); as the first thing in OTS?

Or, maybe a setting got knocked loose on the conversion, like collision-layers.

avatar image ChrisHorrigan · Jun 11, 2015 at 06:46 PM 0
Share

@Owen Reynolds I have tried debugging with Debug.Log and it shows that OnTriggerStay definitely isn't being called. It also looks like my collision layers have not changed -- even the layer collision matrix carried over correctly. It really seems like nothing about my project changed between Unity 4 and Unity 5. I'm gonna have to dig through the Unity 5 update notes or something I think.

avatar image ChrisHorrigan · Jun 12, 2015 at 04:50 PM 0
Share

Weird update: I changed the function from OnTriggerStay to OnTriggerEnter and it did call the function. I changed it back to OnTriggerStay and it didn't call it. Unity 5 must have done something to OnTriggerStay!

avatar image zach-r-d · Jun 12, 2015 at 05:43 PM 0
Share

I'm pretty sure the answer is yes if you're getting OnTriggerEnter, but do you have a Rigidbody attached to the object and/or the trigger? Also, what type of collider is on each?

avatar image ChrisHorrigan · Jun 12, 2015 at 05:46 PM 0
Share

The trigger is a sphere collider, and it is on an object that has a parent with a rigidbody. The collider is a capsule collider, which is the player. No rigidbody there.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sabish-m · Jun 12, 2015 at 06:05 PM

now i am working in Unity 5.. i am using OnTriggerStay function its working fine...

maybe it will be help you...

 #pragma strict
 
 function OnTriggerStay(other : Collider){
 if(other.tag == "MovingBridge"){
 transform.parent = other.transform;
 }
 }
 
 function OnTriggerExit(other : Collider){
 if(other.tag == "MovingBridge"){
 transform.parent = null;
 }
 }




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 sabish-m · Jun 12, 2015 at 06:06 PM

remove both collider and add again in Unity 5...

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 Madhotdog · Oct 20, 2015 at 12:03 PM

Just in case anyone else gets stuck on this issue the problem is related to the following bug: http://issuetracker.unity3d.com/issues/triggercollider-ontriggerstay-is-not-called-for-child-objects

To further note, it appears that adding a rigidbody to the OnTrigger scripted object allows OnTriggerStay events to be called even when its parent object has a rigidbody.

This does not work: -> Parent (has rigidbody) ---> Child (has OnTrigger script)

This works: -> Parent (has rigidbody) ---> Child (has rigidbody, OnTrigger script)

Adding a blank OnTriggerStay method to the parent also will surfice

 public void OnTriggerStay(Collider other)
 {
     // Unity needs this method here
 }

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

7 People are following this question.

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

Related Questions

physics.OverlapSphere colliders 1 Answer

Why does my counter keep going up after pickup is destroyed? 1 Answer

Compound Colliders and IgnoreCollisions 1 Answer

Strange "lock" when setup colliders and rigidbody by scripting... 4 Answers

Collision detection for many colliders 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