godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.71k stars 574 forks source link

Module Initialization - Level Scene is running in-editor #1255

Closed nonunknown777 closed 7 months ago

nonunknown777 commented 1 year ago

Godot version

4.1 stable

godot-cpp version

4.1

System information

Linux

Issue description

When running the code with:

MODULE_INITIALIZATION_LEVEL_SCENE

the code runs in-editor, but that should only happens if the dev uses:

MODULE_INITIALIZATION_LEVEL_EDITOR

Steps to reproduce

Minimal reproduction project

NA

dsnopek commented 1 year ago

Thanks for the feedback!

Unfortunately, this is not what MODULE_INITALIZATION_LEVEL_SCENE and MODULE_INITIALIZATION_LEVEL_EDITOR are for. Just like in Godot modules defined in the engine, any nodes that are registered during any initialization level will run in the editor, and they need to call Engine::is_editor_hint() to control what behavior they want to run in editor or not. In general, GDExtensions aim to emulate how Godot modules work, and this is how it works for Godot modules.

The initialization levels have to do with the process of engine startup, so that things are registered in the right order. For example, some aspects of the editor need to be initialized before we can start registering editor-related classes.

However, I understand your frustration! This is the number 2 complaint from people who are trying to use GDExtension to write gameplay code. This is a problem that needs some sort of answer, but we haven't come up with one yet. One possibility we've discussed is allowing developers to register scripts from godot-cpp (rather than extension classes), which would behave much more like GDScript (or GDNative from Godot 3), however, there's been some debate around whether or not this is a good idea.

nonunknown777 commented 1 year ago

oh thanks for explaining, asked in the chats nobody gave a deep response like that, which makes sense in my mind now, and yeah, in one of your lives not long ago I shared this proposal: https://github.com/godotengine/godot-proposals/issues/573

not much related to this topic in general, but I just think its strange that you need to check if is editor or not, since _ready and _process for example when attached to a node's gdscript doesnt require you that, as a godot user I expect to run my code in-editor only if I say so @tool. And Module initialization level scene (in my mind) was basically saying to the engine: -hey only initialize this code while a game scene starts xD.

So this really needs to be discussed!