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 ![]()

