Hello, I have a few enemy spawners in my levels and I’d like some to have a bigger chance of spawning some enemies and others bigger chance of spawning something else. So I thought I could do something like
@export var spawn_list: Array[SpawnEntry]
class SpawnEntry:
var scene: PackedScene
var probability: float = 1
but then I get the error
Parse Error: Export type can only be built-in, a resource, a node, or an enum.
Your class SpawnEntry has to be derived from a type the error message displays so you can use @export for it.
You could extend from Resource.
class_name SpawnEntry extends Resource
@export var scene: PackedScene
@export var probability: float = 1
You can then rightclick in the Filesystem -> Create New -> Resource and then search for your class_name. This way you can create multiple SpawnEntries and you can set the scene and probability for each in the Inspector.
In your level script you can then use @export var spawn_list: Array[SpawnEntry] and drag all your created SpawnEntries into it from the Inspector.
Resources are good if you want to store data etc. But of course you can write code in them too. They just can’t be instantiated like Nodes.
Using dictionary:
With a dictionary it works too, so you won’t need to create seperate SpawnEntries.
@export var enemies : Dictionary
In the inspector use the pencil icon and set the “New Key” value type to Object and the “New Value” type to float. The Key is the scene for your enemy.