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 greggman · Dec 13, 2014 at 07:14 AM · bugupdatemonobehaviour

How to prevent Update from *not* being called

This is NOT the same as other "Update not called" questions. My Update is called but then later it stops being called.

What should happen I thought....

  1. The first time update is called it should call MakeException

  2. The exception will get caught by the try/catch.

  3. After that every frame Update will still be called and it will print a number

    What happens instead

  4. The first time update is called it should call MakeException

  5. The exception will get caught by the try/catch.

  6. After UPDATE IS NO LONGER CALLED.

I get no notification. I tried adding OnDisable and OnDestroy just to see if Unity was disabling or destroying the script but it's not. Those don't get called until I pick stop in unity so the script itself (the MonoBehaviour) is not getting destroyed by the exception. Never the less Update stops being called

How can I call something like the code below and NOT have it stop calling Update?

 using UnityEngine;
 using System.Collections;

 public class UpdateFailure : MonoBehaviour {

     bool once = true;
     int count = 0;

     // Use this for initialization
     void Start () {

     }

     // Update is called once per frame
     void Update () {
         Debug.Log(count++);
         if (once) {
             once = false;
             MakeException();
         }
     }

     void MakeException() {
         try {
             System.Int32 i = System.Int32.MinValue;
             Debug.Log(System.Math.Abs(i));  // causes an exception
         } catch (System.Exception ex) {
             Debug.LogException(ex);
         }
     }
 }



Comment
Add comment · Show 3
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 Kiwasi · Dec 13, 2014 at 07:20 AM 0
Share

It might be your LogException. Have you tried commenting that line out?

avatar image greggman · Dec 13, 2014 at 07:22 AM 0
Share

I'll try it but why could Debug.LogException cause that. The docs don't mention it as anything special.

avatar image greggman · Dec 13, 2014 at 07:25 AM 0
Share

Well, you were right. Getting rid of Debug.LogException fixed it. Debug.LogError also fails (meaning Update stops being called) where as Debug.Log works

So lame. Spent the last 6 hours trying to make this work :(

2 Replies

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

Answer by tanoshimi · Dec 13, 2014 at 08:01 AM

Do you have "Error Pause" enabled?

"When Error Pause is enabled, Debug.LogError() will cause the pause to occur but Debug.Log() will not."

http://docs.unity3d.com/Manual/Console.html

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
1

Answer by Kiwasi · Dec 13, 2014 at 08:16 AM

Edit: Tried it on my own system (see comments) and the following answer does not hold true. Unsure what the problem is.

Original answer:

The problem is the Debug.LogException. This works by passing an exception back to unity, or something similar. This is much the same as if you had written an explicit throw statement.

I've had similar issues before. Unity seems to be wired so that if a component throws an exception during Update, it just kills that component and keeps running everything else.

In general you should not expect code to continue running after throwing an exception. Exceptions are generally used to indicate fatal errors. If the server cannot be contacted, but this is okay, then you should log a warning instead.

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 greggman · Dec 13, 2014 at 10:02 AM 1
Share

There's no point in having a Debug.LogError or Debug.LogException if all they do is kill your app :( Every other dev environment in existence doesn't stop executing when you call some Log.Error or Log.Execption method. The whole point is to "Log" them. If you want your app to stop after that point you'd either throw the exception again or take some other action.

avatar image Kiwasi · Dec 13, 2014 at 07:34 PM 0
Share

Changing my $$anonymous$$d again. This is not the problem.

The following code works as expected, spam$$anonymous$$g the console with errors

 void Update () {
     Debug.LogException (new System.Exception());
 }
avatar image greggman · Dec 13, 2014 at 07:37 PM 0
Share

You're right. It's the Error Pause option which (a) I didn't know existed and (b) shouldn't have arguably triggered since I caught the error, meaning it's not an error :(

avatar image Kiwasi · Dec 13, 2014 at 07:37 PM 0
Share

Copied your code directly into Unity and it logged an exception as expected, then continued to run update. Not sure what is happening on your system.

avatar image Kiwasi · Dec 13, 2014 at 07:51 PM 0
Share

Error Pause will trigger as long on LogError or LogException, as well as on a thrown error.

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

26 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 avatar image

Related Questions

Why does Scene View not update like Game View? 1 Answer

Update and Awake not being called. 1 Answer

Upgrade check from Unity 5.1.0f3 to 5.1.1f1 failed 1 Answer

New Unity 4.5 Transform Organization Bug? 0 Answers

Script acting weirdly after updating from 2018.2.2 to 2018.3.1 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