Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by AntonStruyk · Jul 26, 2013 at 09:14 PM · cameratriggerpausefixedupdatetimescale

Unity 3.5.7 - 4.2 upgrade: Changing Time.timeScale causes OnTriggerExit & OnTriggerEnter handlers to fire

I have some code in one class to handle pausing that used to work in Unity 3.5.7. We recently upgraded our project to Unity 4.2 and we started seeing this strange behaviour.

In our scene we have a SphereCollider attached to the camera and we have some box colliders that are placed around the world with scripts on them that are reacting to the OnTriggerEnter() and OnTriggerExit() calls.

In our pausing code set Time.TimeScale = 0; to pause the game. When this happens, our camera happens to be inside a BoxCollider that has a script attached to it.

In Unity 3.5.7 (and before) setting the Time.timeScale to 0 and back had no affect on OnTriggerEnter and OnTriggerExit handlers being fired.

In Unity 4.2 as soon as we set the timeScale to 0 the OnTriggerExit() function fires on the box collider's script. In addition when we restore the time (set it back to something non-0) the OnTriggerEnter() function fires. This is causing some nasty behaviour in our game, since we assume the camera is leaving the volume and perform some cleanup on objects in the volume. This used to be the case but now this is happening every time we pause... Not awesome.

I've tried setting the scale to something very small (0.0000001) but non-zero, but that breaks some other code we have that checks to see if the game is paused or not by examining the timeScale. I've also tried modifying the Time.fixedDeltaTime at the same time (setting it to 0 along with the Time.timeScale value), but that only seems to cause the events to fire more often.

I cant' find any reference to the expected behaviour here except that 'FixedUpdate functions will not be called when timeScale is set to zero.'

I'm not sure what to do to avoid it other than hacking in a bunch of guard code that checks to see if we're actually inside the box when the event happens. I'd need to do this in a bunch of places, so it's not exactly making me quake with joy.

Is this a unity bug or expected behaviour? Is there something I can do to make these events stop coming up when the object doesn't actually leave the box bounds?

Comment
Add comment · Show 5
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 Jamora · Jul 27, 2013 at 01:13 AM 0
Share

This does sound like a bug.

Have you considered alternative pausing methods? In a project once I just did

 RigidBody rb;
 foreach(GameObject go in GameObject.Find(typeof(GameObject))){
   rb = go.GetComponent<RigidBody>();
   if(rb != null)
     rb.Sleep();
     //Or alternatively rb.WakeUp(); on resume
 
 }

Though I didn't have a whole lot of GameObjects in there...

avatar image AntonStruyk · Jul 29, 2013 at 02:12 PM 0
Share

I tried to reproduce this in a super-simple project (just a box and a camera) but was unable to get it to happen. It definitely seems like a bug so I've submitted a bug report to Unity.

avatar image grcwar · Aug 02, 2013 at 01:50 PM 0
Share

We are facing the same problem in here.. we manage to workaround the problem setting the timescale to a very low value. But this definetely seems to be a bug, any news from Unity about that?

avatar image eddyjohnson3 · Aug 10, 2013 at 03:02 PM 0
Share

just upgraded to 4.2 This is causing problems for me too. Is Unity going to fix this?

avatar image xeleh · Sep 02, 2013 at 09:35 PM 0
Share

Fixed in 4.2.1

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xeleh · Jul 28, 2013 at 03:30 AM

This change of behaviour is breaking my code too. I think it's a bug and as an urgent workaround I'm doing this:

 private var lastTimeScale : float;
 
 function Awake() {
     lastTimeScale = Time.timeScale;
 }
 
 function OnTriggerExit(other : Collider) {
     var lts : float = lastTimeScale;
     lastTimeScale = Time.timeScale;
     if (lts != Time.timeScale) {
         return;
     }
     // original trigger code starts here
 }

 // The same for OnTriggerEnter()

It works for my case but defensive code like this is nasty... better ideas are welcome.

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

19 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

Related Questions

Stopping FixedUpdate 2 Answers

Orbit camer while paused? 1 Answer

Pause game on Start doesn't quite work 1 Answer

How can i pause gradually from timeScale 1.0 to 0.0 over a second? 1 Answer

How to pause only specific objects/prefabs? 3 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