Get the properties of an exported resource

Godot Version



How do I get the properties of a exported resource with editor hint?
Let’s look at an example:

#its autoload script
class_name Character extends Node

@export var character_stat_res:CharacterStats

class_name CharacterStats extends Resource

var hp:int
var speed:int

extends Control

#get properties without editor hint
func get_character_stats_one():

#get properties with  editor hint

func get_character_stats_two():
	var stats = CHARACTER.character_stat_res as CharacterStats

Are there any workarounds to not create a new variable and still have access to the hint?

Example editor property hint

I don’t think it matters if the resource is exported or not, it doesn’t work because it’s a custom resource. I think it should work because it works with built-in resources. You could try checking Github to see if that’s a known issue.

Some alternative ways to access the properties:

func get_character_stats():
  var hp: int = (CHARACTER.character_stat_res as CharacterStats).hp
var stats: CharacterStats = CHARACTER.character_stat_res

func get_character_stats():
  var hp: int = stats.hp
1 Like

Oh, thank you. I hadn’t even thought about user resources. I guess you’re right.

And thanks separately for the tip about creating a variable at the beginning. I hadn’t thought of that either, and it won’t be a problem since it’s an autoload script.

1 Like

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