How to have editor-only nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

I created a level object as a scene, and I need to display special things in the editor to make its edition more user-friendly.
I tried to add it in the script with get_tree().is_editor_hint(), but because of the way my script works it becomes a bloat nightmare.

So I’m doing this with additional nodes, so the two logics are well separated. While these nodes are handy, I don’t want them to end up in the exported game.

How can I tell Godot not to include a specific node of a scene?

:bust_in_silhouette: Reply From: vnen

On Godot 2.1 you can make an EditorExportPlugin to pick the scene, remove the node you don’t want, re-pack the scene (with PackedScene.pack()) and return it with var2bytes().

It’s a convoluted process, but for such a specific situation I think there’s no easy way.

:bust_in_silhouette: Reply From: kubecz3k

I would suggest simply remove with free or queue_free node in ready if get_tree().is_editor_hint()check fails.

I thought about this solution as well. Should be ok for a small amount of nodes but I would prefer a scalable solution.
Actually, I managed to modify my script so I can integrate the editor code with reasonable overhead without relying on additional nodes. Well, it doubles the script’s size and there are extra calls in a few setters and _process(), but I don’t have any better solution yet.

Zylann | 2016-07-03 11:33

:bust_in_silhouette: Reply From: jackmakesthings

The first thing I’d do is put all your editor-only nodes into one group; that should make it easier to act on them (via get_nodes_in_group or similar). Then have one central script in charge of managing that group - maybe when the scene runs it checks for whether it’s in the editor or not, and frees all the nodes in that group if it isn’t.