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 limdor · Nov 23, 2009 at 11:20 AM · editoreditor-scriptingdebug

Debug.Log doesn't work properly in a ContextMenu function

Hi, I've done a function like this and I have a problem:

[ContextMenu("Calculate PVS")]
void CalculatePVS()
{
    Debug.Log("Calculating the PVS...");
    VeryExpensiveFunction();
    Debug.Log("Calculating the PVS........");
    VeryExpensiveFunction();
    Debug.Log("Calculating the PVS........DONE");
}

It doesn't show the Logs until all the block finish, is there any solution?

The Behavour is:

(Wait alot of time)
Calculating the PVS...
Calculating the PVS......
Calculating the PVS......DONE

And shoud be:

Calculating the PVS...
(Wait time)
Calculating the PVS......
(Wait time)
Calculating the PVS......DONE

Thanks

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
1
Best Answer

Answer by jashan · Nov 23, 2009 at 11:53 AM

I've seen similar behaviors with logging frameworks; the reason is very likely that log statements are somehow batched for performance reasons (e.g. only putting out logging "once per frame" which would mean all log-statements from one frame are sent to the console in a single step; or it may even be that the console batches the log statements in one way or another).

Anyways, instead of waiting for the log statements, you could work with timestamps (which would be what I'd recommend for logging such things anyways). One very convenient way of doing that is using the Stopwatch class the .NET framework provides. For using this, you need to include the namespace System.Diagnostics (which is in system.dll - which for editor scripts doesn't matter but you might be careful using this in Web Players, see also Reducing File Size - Reducing included dlls in the Web Player).

using System.Diagnostics;
[...]
[ContextMenu("Calculate PVS")]
void CalculatePVS()
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
    VeryExpensiveFunction();
    Debug.Log(string.Format("Calculating the PVS - first call took {0}ms", 
                            sw.ElapsedMilliseconds));
    VeryExpensiveFunction();
    Debug.Log(string.Format("Calculating the PVS DONE - took {0}ms", 
                            sw.ElapsedMilliseconds));
}

If you don't want to work with classes from System.dll, you could also create yourself a simple helper class using DateTime.Now or directlyuse DateTime.Now in your code (really depends on how much time-tracking you need to do).

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
Best Answer

Answer by duck · Nov 23, 2009 at 11:41 AM

I don't know whether there's a solution to making the Debug messages show up, but if you're broadly looking for some way to get progress feedback during a long-running editor script, you can use EditorUtility.DisplayProgressBar. In your case you'd probably use it something like this:

[ContextMenu("Calculate PVS")]
void CalculatePVS()
{
    EditorUtility.DisplayProgressBar ("Calculating the PVS", "Calculating - 0%", 0)
    VeryExpensiveFunction();
    EditorUtility.DisplayProgressBar ("Calculating the PVS", "Calculating - 50%", 0.5f)
    VeryExpensiveFunction();
    EditorUtility.DisplayProgressBar ("Calculating the PVS", "Calculating - 100%", 1)
}

Of course, it would be better to have more finely-stepped progress updates actually inside your VeryExpensiveFunction! You also need to use EditorUtility.ClearProgressBar when all your operations have finished to hide the progress bar.

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 Matt Maker · Nov 25, 2009 at 03:02 AM

The behaviour of Debug.Log is slightly different between some Unity3D versions, but if this works for you, it might be the quickest "answer" to your question. Change your Debug.Log calls to look like this:

Debug.Log(Time.realtimeSinceStartup + " Calculating the PVS...");

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

How to record the entire game and user behaviour for a research project? 1 Answer

get folder from selection array 4 Answers

Editor Scripting - Override Scaling 1 Answer

How can i get the center of the entire editor window 0 Answers

Editor window script only works when window is open? 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