No output from Debug.Log

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:

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LearningScript : MonoBehaviour {

     public int myNumber = 9;

    // Use this for initialization
    void Start () {
        Debug.Log(2 + 9);
        Debug.Log(11 + myNumber);
    }


    // Update is called once per frame
    void Update () {

    }
}

I believe Debug.Log is expecting a string, not numerical operations. The + sign is concatenation when using strings

Try

Debug.Log (“Hello” + " world");

Check this toggle

6 Likes

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…

Debug.Log expecting object parameter and automatically call ToString() on result ariphmetic expression

@oleggelezcov Thanks for the correction! @Tigersong_1 remember that a script needs to be attached to a GameObject for it to execute.

Thank you. Right now the only GameObject in my scene is the main camera- is it safe to attach the script to it?

Worked for me. You can just add an empty game object if you have concerns.

It works! Thank you all.

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.

still broken

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.

This may help https://forum.unity.com/threads/tips-for-new-unity-users.701864/#post-5057741

?

Please do not necro posts like this.