Referencing an Animation Throughout an entire scene (Sorta like an global

Godot Version

4.6

Question

You see my scene tree every Animated sprite has the same two animations: “Idle” and “Hovered”, i am trying to make this single script control interaction since im making a horror cooking game and will reuse a lot of mechanics.

I ran into this issue which i believe is simple but i kinda can’t figure it out can anyone help

If you share code, please wrap it inside three backticks or replace the code in the next block:

extends Area2D

class_name Interactable
@onready var Sprite = AnimatedSprite2D
@export var selected: bool = false


func _ready() -> void:
	`	Sprite.animation = "Idle"



func _on_input_event(_viewport, _event, _shape_idx) -> void:
	if !Input.is_action_pressed("Interact"):
		selected = false
		Sprite.animation = "Idle"
	else:
		selected = true
		Sprite.animation = "Hovered"
	

func _physics_process(delta: float) -> void:
	if selected == true and is_in_group("Interactable"):
		global_position = lerp(global_position, get_global_mouse_position(), 25 * delta)

What is the issue you ran into?

my bad here’s the error: Error at (9, 5): Expected statement, found “`” instead.. Basically it’s not able to tap into the animations (btw sorry im new to coding i’ve been a game artist my whole life so spent 4 weeks doing art for this game now jumping into coding

that error is likely refering to this line, you added a single tick ` to the start of the line, this is not understood as GDScript so it errors. Remove the tick.

Another error you may find is this line needs a dollar sign $ so it will try to find a child node named “AnimatedSprite2D” rather than using the class itself.

@onready var Sprite = $AnimatedSprite2D
1 Like

i knew it was simple thanks