Skip to content

feature: load scene to tree, instead of changing to resource#7

Open
MigasEu wants to merge 3 commits into
Maaack:mainfrom
MigasEu:feature/load-scene-to-tree
Open

feature: load scene to tree, instead of changing to resource#7
MigasEu wants to merge 3 commits into
Maaack:mainfrom
MigasEu:feature/load-scene-to-tree

Conversation

@MigasEu

@MigasEu MigasEu commented Jan 30, 2025

Copy link
Copy Markdown

Add a new load method to add the loaded resource to the tree, instead of changing scene to resource directly.
This allows to do changes on the scene before changing to it.

In my case, it allows me to wait for other peers to be ready and spawn the characters before showing the new scene.

Also added a few new signals so that I'm able to add fade effects on top of it.

Add resource to tree instead of changing scene to resource directly.
This allows to do changes on the scene before changing to it.
Also added a few signals so that I'm able to add fade effects on top of it.
@Maaack

Maaack commented May 27, 2025

Copy link
Copy Markdown
Owner

Thanks for the PR! I apologize for the delay in reviewing it. I've been avoiding making big changes to the SceneLoader, since it's so core to the other templates/plugins. It may be some time still before I can give this a good look over, but I haven't forgotten about it.

@Maaack Maaack self-assigned this May 27, 2025
@Maaack

Maaack commented Oct 28, 2025

Copy link
Copy Markdown
Owner

Thanks for the updates. I think adding the scene_changed and scene_changed_to_loading both make sense. The loading_scene_loaded is a bit of an odd name given the context, and I'd recommend scene_change_to_loading_started or something similar and past-tense.

I admittedly don't understand your setup. It sounds like there is a manager (likely an autoload) that is making the call to load_scene_to_tree(), but then I'm confused as to why there is a call to change_scene_to_node_in_tree() as soon as the thread is loaded. I don't understand how this solves the problem stated. If there is a manager waiting for other peers to be ready, then I would expect it would be deciding when to call change_scene_to_node_in_tree(), instead.

Overall, I think a lot of what is being done here could be put into an example level loader, maybe with just the addition of a change_scene_to_node(next_scene : Node) call to scene_loader.gd. For example, here is a level loader from the Game Template. https://github.com/Maaack/Godot-Game-Template/blob/main/addons/maaacks_game_template/extras/scripts/level_loader.gd

The above script could be included in this repo as well, for people that only use this plugin. Another script could then extend its load_game() call with extras. Does that seem like a viable alternative to you?

@Maaack Maaack added enhancement New feature or request question Further information is requested labels Oct 28, 2025
@MigasEu

MigasEu commented Oct 29, 2025

Copy link
Copy Markdown
Author

Yeah, I ended up not even needing the loading_scene_loaded. It was more for keeping the consistency with scene_loaded. Since the loading scene is preloaded anyway, it is a bit unnecessary. We could also just remove it, let me know which option do you prefer.
The change_scene_to_node_in_tree is only called automatically if load_scene is called with _background_loading set to false, which never happen with load_scene_to_tree (see line 142), so yeah, it never happens, so that line on the process method is useless, and confusing. We could either remove it and leave only change_scene_to_resource there, or throw an error, maybe?

Oh, yeah, I guess you're right, that could be handled outside of the plugin. If you prefer to keep it simple and clean, that works for me too.
I did need to add the scene_changed_to_loading and scene_changed signals, to know when to fade in/out and when I'm able to start loading the main scene. Had a problem with another plugin that used get_tree().current_scene getting the main scene ready, and if I didn't wait for the loading scene to load, current scene would be null and break it.

@Maaack

Maaack commented Oct 29, 2025

Copy link
Copy Markdown
Owner

That sounds good to me regarding the signals. I'm hesitant to add the methods, as I think much of that logic can be handled outside of the scene loader by a manager. If you'd like to open a second PR, either here or on https://github.com/Maaack/Godot-Game-Template (for more visibility as a contributor) with just the signals for existing methods, I'd be happy to merge that in pretty quick.

I've added it to my todo list to get an example level manager into this repo. From there, maybe we can discuss what needs to be restructured to make it work for a general use case, or extend it to fit your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants