godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add an `editor_only` property to Node (and remove it from specific uses such as Light3D) #2512

Closed BastiaanOlij closed 2 years ago

BastiaanOlij commented 3 years ago

Describe the project you are working on

Dungeon crawler

Describe the problem or limitation you are having in your project

I very often add objects as visual guides to scenes that are meant to be extended. For instance in this screenshot I've added Left/Right/Top/Bottom labels to easily recognize the orientation of a room I'm working on: image

Right now these nodes are hidden when the game starts but it's still overhead to create these objects, compile their shaders and load images that are only needed when editing.

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

I suggest adding an "editor only" property to the node section of a node. When ticked this prevents the node and any of its children from being loaded in runtime.

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

See above

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

I'm currently working around it by making these nodes available in _ready but it's wasteful

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

No this is a change that needs to happen in Godots scene loader.

Calinou commented 3 years ago

This Editor Only property already exists for certain nodes such as Light3D, but there is no universal toggle that works for all nodes. I discussed this with reduz a while ago and he wasn't really in favor of moving this Editor Only property to Node (I don't remember why).

Xrayez commented 3 years ago

This Editor Only property already exists for certain nodes such as Light3D

Seems like Light2D, Light3D and ReferenceRect:

PS D:\src\godot\gd4> rg editor_only
scene\gui\reference_rect.cpp
40:             if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
64:void ReferenceRect::set_editor_only(const bool &p_enabled) {
65:     editor_only = p_enabled;
69:bool ReferenceRect::get_editor_only() const {
70:     return editor_only;
80:     ClassDB::bind_method(D_METHOD("get_editor_only"), &ReferenceRect::get_editor_only);
81:     ClassDB::bind_method(D_METHOD("set_editor_only", "enabled"), &ReferenceRect::set_editor_only); 
85:     ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "get_editor_only");

scene\gui\reference_rect.h      
41:     bool editor_only = true;
54:     void set_editor_only(const bool &p_enabled);
55:     bool get_editor_only() const;

scene\3d\light_3d.cpp
171:    if (editor_only) {
179:    if (editor_only) {
197:void Light3D::set_editor_only(bool p_editor_only) {
198:    editor_only = p_editor_only;
202:bool Light3D::is_editor_only() const {
203:    return editor_only;
229:    ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light3D::set_editor_only);
230:    ClassDB::bind_method(D_METHOD("is_editor_only"), &Light3D::is_editor_only);
280:    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");

scene\3d\light_3d.h
81:     bool editor_only = false;
102:    void set_editor_only(bool p_editor_only);
103:    bool is_editor_only() const;

scene\2d\light_2d.h
56:     bool editor_only = false;
86:     void set_editor_only(bool p_editor_only);
87:     bool is_editor_only() const;

scene\2d\light_2d.cpp
44:     if (editor_only) {
52:     if (editor_only) {
69:void Light2D::set_editor_only(bool p_editor_only) {
70:     editor_only = p_editor_only;
74:bool Light2D::is_editor_only() const {
75:     return editor_only;
235:    ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light2D::set_editor_only);
236:    ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only);
281:    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");

I discussed this with reduz a while ago and he wasn't really in favor of moving this Editor Only property to Node (I don't remember why).

It makes sense to me to have a dedicated property for this especially when we have editor_description property exposed. If bloat is concern, then editor-only properties can be grouped easily in the inspector, but I don't quite see what else could be added.

Introducing editor_only property also means that classes are likely going to be refactored or rewritten when it comes to code wrapped in TOOLS_ENABLED macro, which is also fine (editor-only code would still be compiled out, it just means that we now have an opportunity to control the run-time behavior).

For instance in this screenshot I've added Left/Right/Top/Bottom labels to easily recognize the orientation of a room I'm working on

See also #115 (can be made to work as editor-only as well).

Calinou commented 3 years ago

Also, following https://github.com/godotengine/godot/pull/46191, we may want to add an enum to control where the node is shown or instantiated. Therefore, instead of adding an editor_only property, I suggest adding the following:

LikeLakers2 commented 3 years ago

The node is shown in the editor and hidden at runtime (or freed to improve runtime performance?).

I don't think either option (hiding it or freeing it) is necessarily better than the other. Perhaps you could split this into "Hide at Runtime" and "Delete at Runtime"?

Calinou commented 2 years ago

Closing in favor of https://github.com/godotengine/godot-proposals/issues/3433, which is a more detailed proposal.