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

Godot Version



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 :"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