get_node: (Node not found: "TimeBeforeGameOver" (relative to "/root/Player").)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By David000

Here is the full error:

E 0:00:05.192   get_node: (Node not found: "TimeBeforeGameOver" (relative to "/root/Player").)
  <C++ Error>   Condition "!node" is true. Returned: nullptr
  <C++ Source>  scene/main/node.cpp:1325 @ get_node()
  <Stack Trace> @ _process()

Here is my code:

extends Area2D

#onready var explosion1 = preload("res://Explosion1.tscn")

var hp = 3
var isDead = false

func _on_Area2D_area_entered(area: Area2D) -> void:
	if area.collision_layer == 2:
		Player.hp -= 1

func _process(delta: float) -> void:
	if hp <= 0:
#		var explosion = explosion1.instance()
#		get_parent().add_child(explosion)
#		explosion.global_position = global_position
		Player.isDead = true

	if Player.isDead == true:

func _on_TimeBeforeGameOver_timeout() -> void:

Here is my world structure:

- Game
   - BG
   - SpawnTimer
   - Player
   - BulletDestroyer
   - UI
      - Score

And here is my player structure:

   - Player
      - Area2D
         - CollisionShape2D
         - TimeBeforeGameOver
      - BulletSpawnPoint
         - Front
      - FireDelayTime
      - CollisionShape2D
:bust_in_silhouette: Reply From: jgodfrey

In order to use a reference like $TimeBeforeGameOver, the script would need to be attached to the parent of the TimeBeforeGameOver node. Looking at your tree, that would mean the script would have to be on the Area2D node. Instead, I assume the script is on the Player node, right? In that case, you’d need a reference like:


Hmmm… Looking at your tree again, I’m not sure I understand what you show as the Player structure. I assume Player is the parent of everything else listed there, right? You show Player, Area2D, BulletSpawnPoint, FireDelayTime, and CollisionShape2D all being siblings, but I assume that’s incorrect?

jgodfrey | 2022-04-18 15:19

All of the items listed are siblings of the player, just a slight error i made, ill fix that.

David000 | 2022-04-18 15:30

All of the items listed are siblings of the player

So, NOT siblings of Player, but children of Player:slight_smile: Anyway,
that’s what I assumed and my original answer should still be correct,
assuming the script in question is attached to the Player node.

jgodfrey | 2022-04-18 15:35

Oh, I forgot to mention the script that i showed is attached to the Area2D node. And then I have a script attached to the parent (Kinematic2D) for the movement and attack.

David000 | 2022-04-18 15:43