Godot Version
4.4.1
Question
As in the title, I have a custom resource with an exported variable. The _init() function, and the methods called inside it, need to be called while the exported variable is set for the Resource to work. I can create an instance of the resource, set the exported variable, and save it. But apparently, when used, the exported variables are only set after the _init() method is called. more details below.
The resource, called TileSetTBInterface, is used to store a tileset and store a dictionary of its terrain data. I want the data for the terrain sets as well as the data of tiles in thoes terrain sets to be easily accessable without needing to call methods every time (I am using the BetterTerrain plugin so getting terrain data is different). The top of the class is defined as:
class_name TileSetBTInterface
extends Resource
const TERRAIN_META = "_better_terrain"
@export var tile_set : TileSet #The tileset that will have its data accessed
var _source_atlas : TileSetAtlasSource# atlas source of tileset (used in many methods)
var terrain_set_data : Dictionary# dictionarys will contain easily indexed data
var terrain_set_tiles : Dictionary
func _init(): #init called upon creation of resource
_source_atlas = tile_set.get_source(0)
_fill_terrain_set_data() #methods called to fill the dictionaries
_fill_terrain_set_tiles()
As far as I know the methods to access the data work, as its been tested with other TileSets outside of this script. I can also create an instance of the resource and populate the exported variable with an already created tileset.
However, when I try to use this resource in another script that requires a TileSetBTInterface the tileset variable is empty, the exported variable seems to be empty and when the _init() function is called the tile_set variable is null (as shown in debug mode), and the methods to fill the dictionaries dont work.
I’ve read in this post from Jakob_Grundnig that the _init() of a new resource is called before the exported variables are then populated. But I need the functions in the _init() to be called (and tile_set to be populated appropriately) before it is used.
How would I go about Initialising this resource with an exported variable.
