Godot Version
4.2.1 stable
Question
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 player.gd:47 @ _physics_process(): Parameter “data.tree” is null.
<C++ Source> scene/main/node.h:413 @ get_tree()
player.gd:47 @ _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?
player.gd (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
anim.play("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:
anim.play("Run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0:
anim.play("Idle")
if direction == -1:
anim.flip_h = true
elif direction == 1:
anim.flip_h = false
if velocity.y > 0:
anim.play("Fall")
if health < 0:
health = 0
player_alive = false
if health == 0 and player_alive == false:
anim.play("Death")
await anim.animation_finished
get_tree().change_scene_to_file("res://menu.tscn")
move_and_slide()
skeleton.gd (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
anim.play("Run")
else:
velocity.x = 0
anim.play("Idle")
if direction.x < 0:
anim.flip_h = true
else:
anim.flip_h = false
move_and_slide()
func _on_detector_body_entered(body):
if body.name == "Player":
chase = true
func _on_detector_body_exited(body):
if body.name == "Player":
chase = false
func _on_death_body_entered(body):
if body.name == "Player" and body.velocity.y >= 0:
body.velocity.y -= 300
death()
func _on_death_2_body_entered(body):
if body.name == "Player":
if skeleton_alive == true:
body.health -=40
death()
func death ():
skeleton_alive = false
anim.play("Death")
await anim.animation_finished
queue_free()
i hope you will help me