Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by numandina · Mar 11, 2016 at 12:45 PM · scripting problemeditor

Parts of code only execute when there is a Debug.Log() statement in them. Why?

Hi.

Throughout my work with Unity I sometimes run into a bug, and a code that isn't executing (I know because a debug log inside doesn't show anything).

To fix I go back in the code and use other Debug.log() statements to get info on my variables, but when I add these suddenly the code that wasn't executed is now executing.

This happens a lot, and I'm at a loss why. Logically maybe the debug.log statement is taking enough time to make the code run correctly, but this indicates a bigger problem. Any help on what I should be looking for when this happens? Thanks.

Here is an example. The editor doesn't show "a" until the previous debug.log() statements are uncommented.

             else if (nameOCE != "Floor" && !nameOCE.StartsWith("Wheel") && !otherOCE.CompareTag("bullet"))
             {
                 
 //                Debug.Log(nameOCE);
 //                Debug.Log(otherOCE.tag);
 //                Debug.Log(gameObject.layer);
 //                Debug.Log(otherOCE.gameObject.layer);
 
                 if (!otherOCE.CompareTag("Dangerous"))
                 {
                     if (otherOCE.CompareTag("future"))
                     {
                         if (mymen.misslev == 9)
                         {
                             if (!mymen.missdo2)
                             {
                                 mymen.finmiss(1);
                             }
                         }
                     }
                     else if (otherOCE.CompareTag("peace"))
                     {
                         Debug.Log("a");
                         if (mymen.misslev == 10)
                         {
                             if (!mymen.missdo2)
                             {
                                 mymen.finmiss(1);
                             }
                         }
                     }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Mar 11, 2016 at 01:28 PM

There's no reason why the inclusion of Debug.Log would make a difference, unless the tiniest timing delay of printing to the console had meant that the value of one of the conditions had changed (which seems incredibly unlikely). However, your code has several logical inconsistencies and redundancy. I'd set about correcting those and see if it makes a difference:

As far as I can tell, the entire logic can be reduced to:

 else if (nameOCE != "Floor" && !nameOCE.StartsWith("Wheel") && !mymen.missdo2) {
   if (otherOCE.CompareTag("future") && mymen.misslev == 9) {
     mymen.finmiss(1);
   }
   else if (otherOCE.CompareTag("peace") && mymen.misslev == 10) {
     mymen.finmiss(1);
   }
 }

How is this being called? In an OnCollisionEnter? It might help to see the whole function.

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 numandina · Mar 11, 2016 at 06:21 PM 0
Share

Thank you for the answer. Yes the code is too long for its own good, but I separated the if statements because it's easier to organize for me since I added a Debug.Log() in every step of the way as some conditions weren't firing (and the code continues beyond the snippet posted, taking into account the tag being "Dangerous").

Indeed it is in OnCollisionEnter. What does that tell you?

avatar image
0

Answer by shlingg · Jul 17, 2016 at 10:24 PM

Did you find a solution to this problem? I'm experiencing the same thing with if statements and while loops!

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

45 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 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

The variables modified in the inspector are not kept on build 0 Answers

Custom inspector. Pick one bool from a list. 1 Answer

After Build Scripts no longer functioning in build or editor 1 Answer

Setting GameObject properties in editor when public script fields are changed 2 Answers

PostProcessingFactory.cs 2 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