0 votes

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> Area2D.gd:21 @ _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:
        $TimeBeforeGameOver.start(1)

func _on_TimeBeforeGameOver_timeout() -> void:
    get_tree().change_scene("res://GameOver.tscn")

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
Godot version v3.4.1
in Engine by (99 points)
edited by

1 Answer

+1 vote
Best answer

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:

$Area2D/TimeBeforeGameOver

by (12,460 points)
selected by

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?

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

All of the items listed are siblings of the player

So, NOT siblings of Player, but children of Player... :) 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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.