Why is my screen black?

Godot Version



Why am I getting a black screen when I start the game? That’s the base question, I’ll post what I get in my error log here:

E 0:00:04.947 get_node: (Node not found: “FloorCol” (relative to “Sprite”).)
<C++ Error> Method failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1476 @ get_node()
player1.gd:4 @ _init()

Here’s my node setup:


Name: MoveScene
Project Type: 2D


    Type: Sprite
    Extends Class: KinematicBody2D
    Type: Sprite
    Extends Class: KinematicBody2D
    Type: StaticBody2D

This is my current player script:

extends Sprite

var speed = 200  # Pixels per second
var floor_position = get_node("FloorCol").position.y   # Get the floor's position when the game starts

func _process(delta):
	var velocity = Vector2.ZERO
	velocity.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	velocity.y = -Input.get_action_strength("ui_up") + Input.get_action_strength("ui_down")
	# Limit downward movement
	if position.y + velocity.y * delta >= floor_position:  
		position.y = floor_position
		velocity.y = 0 
	position += velocity.normalized() * speed * delta

I haven’t added kinematic bodies yet in this session, but they’ll be put in once I solve this. I have had this issue both with and without them.

I’m very much a beginner, so if anyone has any tips I’d be very happy.

You are missing “@onready” before “var floor_position …”

That did help. I don’t know why but I’ll look it up, just copy-pasting and trying to learn as I go for the mostpart. Thank you. :slight_smile:

You can’t declare variables using functions, because those functions need the game to be running to work. The @onready prefix executes the function once when the node enters the scene, just like if you were to put it inside “_ready()”. :slight_smile:

I don’t really understand what that means, but maybe once I get into the lingo more. Still, much appreciated.