Search Unity

No output from Debug.Log

Discussion in 'Scripting' started by Tigersong, Sep 29, 2017.

Thread Status:
Not open for further replies.
  1. Tigersong

    Tigersong

    Joined:
    Aug 11, 2014
    Posts:
    73
    Hello. I'm working on a simple script using Debug.Log and everything seems to be right, but nothing appears in the editor console when I press play. My code is:

    Code (CSharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LearningScript : MonoBehaviour {
    6.  
    7.      public int myNumber = 9;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         Debug.Log(2 + 9);
    12.         Debug.Log(11 + myNumber);
    13.     }
    14.  
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.  
    19.     }
    20. }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I believe Debug.Log is expecting a string, not numerical operations. The + sign is concatenation when using strings

    Try

    Debug.Log ("Hello" + " world");
     
  3. oleggelezcov

    oleggelezcov

    Joined:
    Jan 18, 2013
    Posts:
    13
  4. Tigersong

    Tigersong

    Joined:
    Aug 11, 2014
    Posts:
    73
    Thanks, Jeff! I'm following along with Learning C# by Developing Games with Unity 5.x so I'll be sure to let the author know about this. Incidentally, what can I use to print numbers to the console?

    I tried using strings but still no output. Odd..
     
  5. oleggelezcov

    oleggelezcov

    Joined:
    Jan 18, 2013
    Posts:
    13
    Debug.Log expecting object parameter and automatically call ToString() on result ariphmetic expression
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @oleggelezcov Thanks for the correction! @Tigersong remember that a script needs to be attached to a GameObject for it to execute.
     
  7. Tigersong

    Tigersong

    Joined:
    Aug 11, 2014
    Posts:
    73
    Thank you. Right now the only GameObject in my scene is the main camera- is it safe to attach the script to it?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Worked for me. You can just add an empty game object if you have concerns.
     
  9. Tigersong

    Tigersong

    Joined:
    Aug 11, 2014
    Posts:
    73
    It works! Thank you all.
     
  10. gurbrindersingh

    gurbrindersingh

    Joined:
    Feb 28, 2017
    Posts:
    32
    It's old question though.. still if anyone else faces same problem make sure the gameobject you have attached your script is active. This is the most possible reason.
     
  11. J_S_link

    J_S_link

    Joined:
    May 8, 2020
    Posts:
    3
    still broken
     
  12. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Tried this?
    Otherwise, make sure the function you have your log statement in is being called, and if it is, then make sure any conditional logic around the log statement is true.
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  14. TheSpaceWorm

    TheSpaceWorm

    Joined:
    Nov 25, 2022
    Posts:
    1
    ?
     

    Attached Files:

  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Please do not necro posts like this.
     
Thread Status:
Not open for further replies.