Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Profiler showing LogStringToConsole, what is that?

Discussion in 'Editor & General Support' started by Ensutee, Mar 31, 2014.

  1. Ensutee


    Apr 11, 2013
    I'm having a weird issue.
    The aim is to create a line of sight effect for our 3d top-down dungeon crawler. We want to hide terrain that the character is not able to see. To do this we render the scene twice;
    (1) with a single green light at the player illuminating everything it can see,
    (2) with all other lights turned on except the green 'vision' light.

    afterwards in OnRenderImage we graphics.blit the normal scene into a custom fragment shader which uses the green value of a pixel in the first render in order to dertermine whether or not to show the pixel in the second render.

    pratically this is achieved through the following piece of code in a script attached to our main camera:

    Code (csharp):
    1. void OnPreRender() {
    2.     //Get a list of lights
    3.     lights = FindObjectsOfType(typeof(Light)) as Light[];
    5.     //disable all lights except the LoS light
    6.     foreach (Light light in lights) {
    7.         light.enabled = false;
    8.     }
    9.     sightLight.enabled = true;
    11.     //move the second camera and render the line of sight info
    12.     lightCam.transform.position = transform.position;
    13.     lightCam.transform.rotation = transform.rotation;
    16.     //enable all lights and disable the LoS light
    17.     foreach (Light light in lights) {
    18.         light.enabled = true;
    19.     }
    20.     sightLight.enabled = false;
    21. }
    23. void OnRenderImage(RenderTexture src, RenderTexture dest) {
    24.     Graphics.Blit(src, dest, matLos);
    25. }
    This is all fine and dandy, however, when we took a look in the profiler we saw the following:

    Nothing is showing up in the console and we are doing no prints or debug.log, basically it's using about 16 ms on an unknown process. I tried googling it yet nothing came up. What we have managed to debug:
    it goes away if
    Code (csharp):
    is commented out, OR if
    Code (csharp):
    1. //enable all lights and disable the LoS light
    2. foreach (Light light in lights) {
    3.     light.enabled = true;
    4. }
    5. sightLight.enabled = false;
    is commented out.

    I really hope you guys can help us out as we seem to be unable to firgure out what is causing this.

  2. Acegikmo


    Jun 23, 2011
    Sounds like something editor related. Have you tried it with the profiler off or simply running it in a build?


    Apr 2, 2013
    Finding objects takes too much cpu time, better find all lights at the start or awake callbacks. Also, avoid foreach, it's much slower than a regular each loop.
    As for the camera logging things, this might come from within the engine if the specified camera renders something twice in one frame. I would suggest to make the other camera render after the main one ( and set to render only a layer where only the line of sight lights are. Blend both images with multiply. Problem solved :D
  4. Ensutee


    Apr 11, 2013
    aHA! we have identified the culprit!
    For our second 'lineofsight' light we had culled all layers except one. Deferred lighting does not support culling of more than 4 layers on a light. This message was only sent to the console occationally, however, it was spamming the editor log, which was causing the frame dips and the messages in the profiler!

    In case this happens to anyone else; the messages was found by clicking on the context menu of the console (small arrow and three lines in the top right) and opening the editor log.

    Thanks for your input and help :)
  5. febinmathew


    Nov 2, 2016
    i am having the same problem.. So what should i do with the Editor Log File?
  6. avi9111


    Feb 24, 2016
    Let me guss, you were using NGUI as me. UICamera.Update() is a item direct to NGUI's camera
    First of all, these multi log show out, i guess it was relatived to ngui, cause after button click will show these log

    Shortly, I figure out all the problem is caused by these 2 problem, one is info, another is error, thought they were log by my colleagues (the top figure was a problem which occure occasionally)

    Finally, i fixed 2 problems cause in my scripts.(such as use LogManager to replace Log.Error(""))

    Althought there were still much performance issue in my project, but the LogStringToConsole issued was fixed, and the profiler seems good, and I'm sure now the LogStringToConsole is a man-made problem.
    (issues need to be confirm:Instantiat for gameobject, and LoadingObject for NGUI)
    Your problems may not casue by these 2 scripts, but I hope these messages could help.

    At the end, for these case, I find out , console log is a significant problem especially the third party components, NGUISis definitely a third prty component
    bigmonkgames likes this.