15

I am trying to print a simple statement using C# on Unity Console but i don't know why it is not printing. enter image description here

1
  • 1.or else create a c# script file here in the project window enter image description here 2. just drag the script file and add to ur object this worked for me Commented Jun 3, 2018 at 8:27

4 Answers 4

32

If print does not work, Debug.Log will not work either so that's not the problem.

These are the possible reasons why print is not showing in the console:

1.Script is not attached to a GameObject.

enter image description here

2.The GameObject the script is attached to is not Active. Activate it from the Editor.

enter image description here 3.The NumberWizard script is not enabled. Enable the script.

enter image description here

4.The log toggle is not checked.

enter image description here

From your screenshot, both Debug, Warning and Error messages are enabled, so we can exclude what's in 4.

Sign up to request clarification or add additional context in comments.

3 Comments

You Are life savior.. The third one works . God bless you
Thanks a lot, it worked. I had to delete the script I created and used the add component to create a new script.
I'm in build 2019.2.17f1 on Win10 Pro and saw that my log toggle (in your step 4) was accumulating messages as the number indicating how many messages are present was increasing, but they were not actually displaying in the console. The same messages would successfully display in my custom in-game console. Restarting Unity fixed the issue. I might report this as a bug to Unity later if I have time, but just an FYI for posterity
5

Pressing "Play"

According to this link, print() or Debug.Log, only will work with the following conditions

It seems that the key piece of information I was missing was that Debug.Log writes to the console only when you run the game from within unity by pressing the "play" button above the game view.

I was running my game by pressing Ctrl-B, or pressing "Build & Run" in the Build Settings window. In that case, it will only output to the log file

So you have to hit the play button above the game view, not by using the "Build & Run".


Check your filters

According to this link, you should also check your filters enter image description here

5 Comments

No. This is Unity3D
System.Console.WriteLine("your string here"); is also not working @Svek
and i am pressing Play button.Nothing Happens
@Programmer solution works... script is not attached to the object
Which log file? Player.log? Can't find it there either
1

Have you tried using Debug.Log? Also, you can also use these for specificity: Debug.LogWarning and Debug.LogError. Also, make sure this script is attached.

E.g. Debug.Log("Started");

Hope it helps!

5 Comments

If print and Debug.Log don't work, probably, your code isn't getting called.
Debug.Log and Print both are not printing on Console. @mindOfAi
Can you add a breakpoint on your Start() method? Make sure it's getting called.
Programmer solution works... script is not attached to the object
Yeah, I stated it in my answer that you should make sure the script's attached.
0

First thing to check that your Script are not attached to the object assuming everything is installed to build (.NET SDK, C# extension and MonoProject).

  • Click object as shown "Hierarchy" panel on the left and choose one of objects.
  • Click "Add Component" at the left bottom panel. Choose scripts and add your script file
  • Then add your debug message to code, i.e. Debug.Log("here is my debug message.."); and Run again.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.