Using @export with a type from preload()

Godot Version

Godot 4.2

Question

I have following code:

const ModelSpawner = preload("res://model_spawner.gd")

@export var model_spawner: ModelSpawner

Then if I try to drag/pick model_spawner, inspector does not allow any objects with script res://model_spawner.gd,
image
even if they exist
image

Is there a way to fix it without using class_name?

if its already available via the preload as ModelSpawner why would you need to import it again as modelSpawner? both are esentially doing the same thing.you could just add class_name ModelSpawner to the top of your script and you should be able to access it directly from any script in the project via ModelSpawner.yourmethod() or ModelSpawner.yourvariable syntax

1 Like

You need to use class_name to handle this I’d say

1 Like

because i want to have a reference to an object on the scene of that specific type, without having to add that type to global namespace.