viewport Y NaN (2D)

Godot Version

v4.7.1

Question

I’m new to Godot Engine, and I’m trying to learn by making a simple Space Invaders-style game. I’m having a problem with the viewport. When I log the viewport, the X value is correct, but the Y value is NaN. Here’s the code I have so far. I’ve included a screenshot of my settings.

My code :
using Godot;
using System.Collections.Generic;
using System.Linq;
using System;

public partial class ScrollingBackground : Node2D
{
[Export]
public float Speed = 100f;

[Export]
public Camera2D MainCamera;

[Export]
public bool isRandom = false;

private List<Sprite2D> parts;
private Vector2 viewportSize;
private RandomNumberGenerator rng = new RandomNumberGenerator();

public override void _Ready()
{
	viewportSize = GetViewportRect().Size;
	GD.Print($"Viewport size: {viewportSize}");
}

The result of GD.Print : Viewport size: (1920, NaN)

I searched but couldn’t find this issue on this forum or any other, and I also asked the AI, which didn’t find anything either…
Thank you in advance for your help :slight_smile:

If you turn off the embedded play and run the game again, do you still see NaN?
I had similar issues before, and disabling embedded window eliminated these issues completely. Give it a go.


Make sure that’s turned off and try again.

Hi ! Thank you very much ! Now it’s working :star_struck:

The irony is that right before working on the feature where I needed the viewport, I actually looked into how to put my run window in the same window because I was sick of switching back and forth between them :sweat_smile: