Can I create a class object with .new in place of a dictionary value

Godot Version

Latest

Question

I don’t have access to my PC at the moment so I’m coding by memory. I’m wondering if I can declare a class type in place of the value element in a dictionary as shown below:

@onready var construct_recipe = { ConstructHousing.HOUSE_HOVEL :	Building.new("Hovel", "Basic homestead", Vector2i(3,3), [Vector2i(ResourceTracker.MaterialType.LOG, 10)])}
1 Like

Yes you would need to overwrite the _init function. This isn’t recomended, especially for Node types as it will be un-instantiatable outside of scripts using .new() with the required parameters filled in.

1 Like