Hoping for feedback on if what I’m describing is scalable/obviously terrible as I think I’ve gotten myself confused with instancing
I’ve been watching tutorials and exploring data/instancing options like using custom resources and PackedScenes.
I often see recommend a workflow where you create a Scene and then pass it data via a custom resource.
Here’s what I’m envisioning after seeing different options:
- Create a custom resource: GameItemData for reach object that will be in the game (stone.tres, iron.tres, copper.tres etc…)
- This has variables like health, texture, icon, name etc…
- This has has an export variable for a generic packed scene: GameItemTemplate.tscn
GameItemTemplates have a function like:
func set_up_instance(data: GameItemData):
var self.texture = data.texture etc....
My workflow would then be to make a custom resource for Stone, Copper, Iron etc…and then use a Spawner class that takes a GameItemData:
func spawn_single_game_item(_item_def: GameItemData):
var item_instance = _item_def.game_item_template.instantiate()
item_instance.set_up_instance(_item_def)
add_child(item_instance)
I’m trying to avoid a scenario where I have to make a Node2D for Copper, then one for Iron and then the Spawner class uses those individual PackedScenes instead of just the resource.