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 jjobby · Jul 09, 2010 at 07:12 PM · debuglog

Is there a way to set Unity to write message log when the calculation has Infinity or NaN?

I've written a simple soccer simulation. It works without any error log from Unity. But I saw that the AI didn't have good decision behavior. So, I decided to check some variables with Debug.Log I found that some of them are infinity or NaN due to variable error or math error in my math method. What surprised me was that the simulation was still working and Unity didn't show any error message at all. Even if those variables were often used (comparing or dividing). o_O

I've already fixed the problem I found. But I'm worry that there may be more math error like this in my code which I still can't find. Is there a way to tell Unity to notify the user when the calculation has infinity or NaN?

Thank You

Comment
Add comment
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

3 Replies

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

Answer by Cyclops · Jul 09, 2010 at 07:42 PM

Actually, it isn't float.Infinity, it's Mathf.Infinity. And unfortunately, that only represents positive Infinite values, you would also need to compare to Mathf.NegativeInfinity.

A slightly better way would be:

if (float.IsInfinity(myFloat) || float.IsNaN(myFloat))
    Debug.Log("wups");

float.IsInfinity() checks for both positive and negative values of Infinity. Negative Infinity - what a concept...

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 qJake · Jul 09, 2010 at 09:02 PM 0
Share

Oh, you're right... I didn't have access to a compiler when I wrote my answer, and I wasn't sure where NaN and Infinity were stored, but you're right.

avatar image
1

Answer by qJake · Jul 09, 2010 at 07:17 PM

No, you can't just notify randomly when any variable is equal to something, but you can do this to check each individual float:

if(myFloat == float.Infinity)

or

if(myFloat == float.NaN)
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 qJake · Jul 09, 2010 at 08:55 PM 0
Share

Disregard this, it's incorrect. See Cyclops' answer for the correct way.

avatar image
0

Answer by Mike 3 · Jul 09, 2010 at 08:13 PM

Most of the time you should be checking if you're dividing things by zero - that's when things really go wrong. It'll save you time later if you check if divisors are zero before using them, and throw errors or modify the values if they are

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

No one has followed this question yet.

Related Questions

Have my debug log saved to a .log file in build. 2 Answers

Debug.Log Override? 3 Answers

Reading the profiler log 0 Answers

Debug.Log is causing an Assert 2 Answers

Debug.Log print order, or Awake vs Start issue? 1 Answer


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