Get_tree().change_scene_to_file error Parameter "data.tree" is null

Godot Version

4.2.1 stable


I’m beginner in Godot, I’ve looked everywhere for a solution, but I can’t find one, someone says it’s a bug. Error is: E 0:00:07:0670 @ _physics_process(): Parameter “data.tree” is null.
<C++ Source> scene/main/node.h:413 @ get_tree() @ _physics_process()

I wanna play animation of death then leave to menu. i write “await anim.animation_finished”. without this line of code, scene is changing. maybe it’s really bug of engine? (end of the code is error)

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

@onready var anim = $AnimatedSprite2D
var health = 100
var player_alive = true
func _physics_process(delta):
	if player_alive:
		if not is_on_floor():
			velocity.y += gravity * delta
		# Handle jump.
		if Input.is_action_just_pressed("ui_accept") and is_on_floor() and velocity.y >= 0:
			velocity.y = JUMP_VELOCITY"Jump")

		# Get the input direction and handle the movement/deceleration.
		# As good practice, you should replace UI actions with custom gameplay actions.
		var direction = Input.get_axis("ui_left", "ui_right")
		if direction:
			velocity.x = direction * SPEED
			if velocity.y  == 0:"Run")
			velocity.x = move_toward(velocity.x, 0, SPEED)
			if velocity.y  == 0:"Idle")
		if direction == -1:
			anim.flip_h = true
		elif direction == 1:
			anim.flip_h = false
		if velocity.y > 0:"Fall")
	if health < 0:
		health = 0
		player_alive = false
	if health == 0 and player_alive == false:"Death")
		await anim.animation_finished
	move_and_slide() (there is no bugs, but just in case)

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

var chase = false
var speed  = 100
var skeleton_hit = false
@onready var anim = $AnimatedSprite2D
var skeleton_alive = true

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
	var player = $"../../Player/Player"
	var direction = (player.position - self.position).normalized() 
	if skeleton_alive == true:
		if chase == true:
			velocity.x = direction.x * speed"Run")
			velocity.x = 0"Idle")
		if direction.x < 0:
			anim.flip_h = true
			anim.flip_h = false
func _on_detector_body_entered(body):
	if == "Player":
		chase = true
func _on_detector_body_exited(body):
	if == "Player":
		chase = false

func _on_death_body_entered(body):
	if == "Player" and body.velocity.y >= 0:
		body.velocity.y -= 300
func _on_death_2_body_entered(body):
	if == "Player":
		if skeleton_alive == true: -=40
func death ():
	skeleton_alive = false"Death")
	await anim.animation_finished

i hope you will help me

You’re doing it the hard way; use this
Add this to your scene.

func death_animation_finished ():

After that, go to the death animation and Add_Track/Call_Method_Track
Next, select the node that has the script and connect death_animation_finished.
the function will run if the animation goes over that key.

I’m a little dumb and beginner and I don’t understand how to do it . so i add this function to my level script (or i need to do that in player script?)
i have death animation by animatedsprite2d and i don’t found add track/call method track
so i add animationplayer

and found this but i don’t know what to do after, can you help again please?)

Alright, if you’re using that, it’s much easier in your AnimatedSprite2D node. Go to Signals, and you’ll see the _animation_finished(). Connect that to the player.

func _on_animated_sprite_2d_animation_finished():
    if (player_alive == false):
1 Like

thank you bro it works

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.