godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 77 forks source link

Allow running custom logic when entering initial scene / changing scene #10860

Open TML233 opened 18 hours ago

TML233 commented 18 hours ago

Describe the project you are working on

A multiplayer game with standard autoloaded manager.

Describe the problem or limitation you are having in your project

When running a specific scene from the editor or the command prompt, the scene running is not the home scene set in the project settings. I want the game to detect which scene is about to run as the current scene, execute some code to set up extra things like a single-player test mode, and take over how the scene is put in the scene.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It allows user to run custom code when a new current_scene is about to added into the tree, and take over how the engine put the new current_scene in the tree.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add a new_current_scene_adding_enabled to set whether the default add_child code for the new current_scene will be run. And add a few signals in SceneTree such as: new_current_scene_adding new_current_scene_added to let the autoloaded nodes know it's happening and run custom code.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, there's no callback when the new current_scene is adding or added. Only a generic node_added signal is present.

Is there a reason why this should be core and not an add-on in the asset library?

This improves how the users can interact with Godot's built-in scene changing and scene loading process. It allows users to work better with the editor's "run specific scene" feature.

### Tasks
KoBeWi commented 13 hours ago

There is addon for that: https://github.com/KoBeWi/Godot-Custom-Runner

Zireael07 commented 4 hours ago

There seems to be an addon for almost everything :laughing: