Understanding how to use @export and the scenes not yet in the Scene Tree

Godot Version

v4.2.2.stable.official [15073afe3]

Question

Hi y’all!

I am making this little top-down shooter, and I was hoping I could add a scene for a combat room’s geometry, then drag and drop scenes from FileSystem to mix and match spawn patterns and doors. However, this has led me to realize I may not be understanding something about scenes/resources/etc.

Why can I not just @export a type, then drag and drop it into a scene? My gut tells me okay, it has to exist in the scene for this to work. That is okay, I can always just create copies of these scenes and mix and match them that way. But ideally, I can change the geometry/nodes by dragging and dropping.

Now, for pure data, like floats and ints that control spawn timers and health, I am using a custom resource I ca
progress
n drag into the scene. But how can I do the same for things that have a “physical” presence in the Scene Tree? Stuff that has a Transform?

Thanks for any help you can provide! Here is a .gif of what I mean, please let me know if can further clarify.

Im not quite sure what you are trying to achieve. if you want to export a scene in the inspector you can do this:

@export var packed_scene: PackedScene

you still need to instantiate the scene and add it to the scene-tree, or you add it as a child of the scene and reference it with the following:

@export var my_node: Node
@export var my_node_3d: Node3D

If you want to drag already existing scenes into your current scene you can just drag them either into the SceneTree or in the Game-Window

I can clarify: I want to assign a node in a scene from the FileSystem. I want to able to assign geometry to the scene from outside of the scene.

That wont work. If you want to reference a scene you need to put it in the scenetree first. Resources can be dragged right into the inspector

1 Like

Thanks! I see. So it has to exist in the scene in order to be referenced.

And I would imagine Resources would not make sense for something like a Node3D or geometry?

not if you want to design levels inside the editor. You can have a look at GridMap, maybe this is what you are looking for

You can reference a scene from the file-system as a resource called “PackedScene”, but as i said you have to instantiate it and add it to the scene-tree manually

1 Like

I did look at GridMap, but perhaps the best solution here is just to make some scenes that have modular pieces, and drop them into the scene as needed.

What I was trying to achieve was to be able to make the levels as easy as “use this floor, with this Path3D node for spawns, and these doors for after combat is done”.

I think just making these and then adding them manually to the scene will work for me. Thank you so much for the quick response and clarification!

1 Like

To the point of “you need to put it in the scenetree first,” note that this can be accomplished via code as well.

Say you have a Packedscene you want to add with certain parameters determined. For example
In your current scene script:

var new_scene = preload("res://scene.tscn").instantiate()
new_scene.var_to_change = this_thing
...
add_child(new_scene)

And this new scene will be added into your scene tree with the adjustments you chose to make. But this time without manually dragging and dropping via @export.

2 Likes

Thank you!