Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People more expert in Godot than me: is there some way we can refer to the other scene other than by file path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm imagining here is: can we make it possible to drag a
tscn
file onto the canvas and then have a block representing a different scene? Or a dropdown list of alltscn
files in the project, except the current one and scenes that are part of the plugin?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another way to do is to export a PackedScene variable packed scene. It will allows the user to assign the scene in the inspector. Should we update and use this approach instead? (Although I'm not the expert)
During my research, I found three ways to switch scenes: T35706. Hopefully, we can get more input from the experts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is right to do this in the block coding canvas (as you have done) not to go to the inspector. I was hoping we could do something similar to how we can drop nodes into the canvas to get a block that represents that node.
I did some brief experiments with this... If you have a node that exports a variable of type
PackedScene
, then assign a scene to it, it gets represented as (wrapped for legibility):I feel like it ought to be possible to define a value block that gets serialised in a way that refers to an external scene in this way. Then this
switch_scene
block would accept a parameter of type PackedScene. And for bonus points we would give it a dropdown of all scenes in the project, like we do for parameters of type node or group.Unfortunately block parameter types are expressed as Variant.Type enum members and a
PackedScene
is just anOBJECT
. There's no analogue toNODE_PATH
.As well as the drag-and-drop idea, another reason it may be nice to store the reference to another scene in a way that Godot itself understands to be a reference to a file rather than just a string is that Godot knows how to update all such references if you rename the scene.
Anyway... What I'm suggesting is of course all way more work than adding a switch_scene block whose parameter is a string. And having the block at all would make a whole world of things possible which currently aren't. So all my suggestions here should probably be considered further work for another time…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in the same way as the more sophisticated alternative to drag&drop sounds that I described in #166 (comment)
I think that we should add a
class_name
field to the block definition, that will pair with thevariant_type
field for the case where the variant is of typeOBJECT
. This is the same Godot has for typed arrays:Then when dragging from the Filesystem to the block canvas:
tscn
orscn
, add a value block of variant type OBJECT and class name PackedScene.In the same way, the holes or slots can be enhaced to allow a specific class name when the variant type is OBJECT. Then we could do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, a PackedScene is a
Resource
. SceneTree (what you get fromget_tree()
) provides 2 methods for changing scenes - from a file path, and from a PackedScene.In code you might do it like this:
With blocks we kinda need to be specific about what kind of
Variant
the parameter is, so we'd need to do one or the other. @manuq has some suggestions on handling that if we want to usePackedScene
s.I like the idea of loading a
PackedScene
withchange_scene_to_packed
, but then you'd have to tackle the whole part of creating a scene with a block usingload
. It would be very similar to theget_node
block, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think #305 helps
get_tree().change_scene_to_file(scene)
:)