I created a CanvasLayer2D called Game Over Screen to make a game over screen which contains a restart button and a animation when the scene is played. In my World script I made so when the player dies the it will add the child Game Over Screen to the World scene using a PackedScene, though when I die it the Game Over Screen doesn't show any of my animations and just shows a restart button. How fix this issue where my animations are not playing when my World script adds the Game Over Screen scene to my World scene?
Code for World scene below:
extends Node2D
const PlayerScene = preload("res://src/Player.tscn")
export var game_over : PackedScene
onready var camera := $Camera2D
onready var player := $Player
var player_spawn_location = Vector2.ZERO
func _ready():
player.connect_camera(camera)
player_spawn_location = player.global_position
func _physics_process(_delta):
if player.health <= 0:
var game_over_screen = game_over.instance()
get_tree().current_scene.add_child(game_over_screen)