Get custom type without preloading

Godot Version

4.2.1 stable

Question

I have a script Player_State.gd that is instanced with the root scene. I want to get property hints from the editor to keep things easy. Is the code in the screenshot the best way to do this, or is there a way to do this without pre-loading the script in every script that interacts with the instance of player_state in the root scene?

# Get script
const Player_State = preload("res://scenes/Player_State.gd")
# Assign type to instance of script
@onready var player_state: Player_State = tree.get_first_node_in_group("state")

In Player_State.gd, add the following line:

class_name Player_State
3 Likes

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