How do i use Preload

Godot Version

Version 4.2.2 Stable

Question

How does preload work, I am trying to play an animation from a diffrent scene (My player scene to my death scene with the script,) and when I use preload it gives me an error saying “unexpected preload,” how do I fix this?

Preload is usually used for storing variables (in the project settings), or to preload a texture. If you could give more info about what you are trying to do, maybe I can help you find a better solution.

i use preload like:

const scene = preload("scene_path")
#or
const img = preload("image_path")

preload() returns file and works like load() but loads before start of the game

Hi,What I am trying to do is My player scene and my killzone scene, my player scene has all the animations and i was thinking if i could add it to the killzone script.

func _on_body_entered(body):
timer.start()
animation_player.play(“Death”)

func _on_timer_timeout():
get_tree().reload_current_scene()

But this didnt work and when i searched preload it said unexpected preload.

I think I understand, if you want to play the death animation from the killzone scene, I would:
Define the player in the killzone (by making character unique or getting character from get_tree()) and then create a function in character script to call death animation, would look something like this:

@onready var character = %character

func _on_body_entered(body):
 character.play_that_animation()

and then in the character script have:

func play_that_animation():
  animation_player.play(“Death”)