Debug text

BeginnerProgrammer

You can print debug text at runtime with DebugText. For example, you can use this to display a message when a problem occurs.

Note

Debug text is automatically disabled when you build the game in release mode.

In the Update method of your script, add:

  1. DebugText.Print("My debug text",new Int2(x: 50, y: 50));

Where x and y are the pixel coordinates to display the text at.

The debug message is displayed when you run the game.

Debug text

To hide debug text, use:

  1. DebugText.Visible = false;

Example script

The following script checks that the texture MyTexture is loaded. If it isn't loaded, the game displays the debug text "MyTexture not loaded".

  1. using Xenko.Core.Mathematics;
  2. using Xenko.Engine;
  3. using Xenko.Graphics;
  4. namespace MyGame
  5. {
  6. public class Script : SyncScript
  7. {
  8. public Texture myTexture;
  9. public override void Start()
  10. {
  11. // Initialization of the script.
  12. myTexture = Content.Load<Texture>("MyTexture");
  13. }
  14. public override void Update()
  15. {
  16. if (myTexture == null)
  17. DebugText.Print("MyTexture not loaded", new Int2(x: 50, y: 50));
  18. }
  19. }
  20. }

See also