@export var room_pool:Array[PackedScene] = [ preload("res://testRoom.tscn") ]
@export var weights:Array[int]= [1]
And you can probably guess it, it’s gonna be for a procuderal generation of some kind of dungeon. The rooms are scenes with tilemaps and stuff, the weights are gonna detemine how much a room is gonna be used in the procedural generation over another.
But I can’t make the weights array automatically have the same weight as the other one, and I can’t give it default values. I’d love something like
and have this still be adjustable with drag and drop in the scene. Is this possible? I experimented a bit with resources, but I haven’t figured out yet how it works in Godot. Is there a cleaner way? How would you guys do it?
dictionaries don’t work as I would like them to. After all I’m exporting this variable and accessing from the scene, and they don’t even let me select packed scene.
I believe resources allow you to what you’re looking for, if I understood.
Create a new script, and in script extend from Resource. Put in some @exports there, like @export var myScene: PackedScene.
Then, in the editor, you can create a new resource, and in the list you can find this new resource you created. You can also, in a scene, @export var myResourceArray: Array[MyResource] and in the inspector, you can then add elements to this array and also edit the properties of the elements you added.
Thanks, I got it to work with resources. They need a few extra clicks in the scene inspector though, so now I gotta figure out which implementation I prefer…
You can use Array[Dictionary], which is untyped and the best you’ll get cause you can’t create a typed dictionary with two types (int and PackedScene) for the values.
If you really want an ID, weight, and scene, you may need to create a class_name’d resource instead.
extends Resource
class_name RoomData
@export var id: int
@export var weight: int
@export var scene: PackedScene
# in pooling.gd
@export var room_pool: Array[RoomData]