Search code examples
c#godotgodot4

Can't print to console in Godot 4 C#


I create a new project, add a root Node2D called 'Level' and attach a script:

using Godot;
using System;

public partial class Level : Node2D
{
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Console.WriteLine("hello");
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
}

After running the game, nothing appears in the output: screenshot of output (I do have all the output types enabled)

When I try throwing an exception from the function:

public override void _Ready()
{
    Console.WriteLine("hello");
    throw new Exception("test");
}

Then we do see the error. sc of output

What am I missing here? Thanks in advance.


Solution

  • using static Godot.GD;
    
    public class Test
    {
        static Test()
        {
            Print("Hello"); // Instead of GD.Print("Hello");
        }
    }