custom class defined:

variable cast as custom class:

Error Message I get:

Greetings All! I have created a custom class called 'Player' but whenever I cast a variable as the Player class I keep getting the error that the class is not a valid class. I believe I have followed the way to do this correctly. Can anyone suggest anything I could have missed?

Thanks for you time

Greetings! :) Your class is named Player (uppercase P) while you later refer to is as player (lowercase P). Names in GDScript are case sensitive, so you should take care to be consistent with case:

onready var player: Player = $Player # uppercase P in class name

hey > @xyz said:

Greetings! :) Your class is named Player (uppercase P) while you later refer to is as player (lowercase P). Names in GDScript are case sensitive, so you should take care to be consistent with case:

onready var player: Player = $Player # uppercase P in class name

hey there! Thanks for your response, sO i have just corrected that, but still the same thing:

Can a custom class be accesses globally or only by children of that node? Do I have to save the script in a different way?

It should work. The class name should be accessible globally. Make sure that Player script is saved and doesn't contain any errors itself.

@xyz said: It should work. The class name should be accessible globally. Make sure that Player script is saved and doesn't contain any errors itself.

Yep, all saved and no errors in the player script. Do you know of anything else I can check?

Maybe trying assigning it in _ready and just set the type in the definition?

var player : Player;
func _ready():
	player = $Player
a year later