Godot Version
4.2
Question
I have 2 Questions:
- Why does on_body_entered run twice?
- Why is the ‘node not found’, despite both print statements show the path twice?
extends Area2D
@export var next_level : PackedScene
@export var player_path : NodePath
@export var camera_path : NodePath
func _ready():
self.body_entered.connect(_on_body_entered)
func _on_body_entered(body):
if body is CharacterBody2D:
var root = get_tree().get_root()
var old_scene = root.get_child(0)
var next_scene = next_level.instantiate()
print(player_path)
var player_instance = get_node(player_path)
var camera_instance = get_node(camera_path)
root.add_child(next_scene)
player_instance.reparent(next_scene)
camera_instance.reparent(next_scene)
old_scene.queue_free()
Error
E 0:00:07:0317 Door.gd:17 @ _on_body_entered(): Node not found: "../Player" (relative to "/root/Root/OverWorld/Door").
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1638 @ get_node()
<Stack Trace> Door.gd:17 @ _on_body_entered()
Door.gd:21 @ _on_body_entered()
Console shows this twice when the player path is printed:
../Player




