How can I check If tool script is running on editor?

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

Suppose I have two nodes like below:

Node2D (with exported ImageTexture)
ㄴTextureFrame

and I did some job to do like below:

when: Node2D.ImageTexture is changed **in editor**
→ Change TextureFrame.texture to have same texture

for this I changed my script to have tool keyword on top of my script, but the problem is…

After struggling with various bugs what I’ve made I found there’s no way to determine whether the script is running in editor or exported game. Because the script is originally created for in-game behavior of moving Node2D[1], Saved project would have changed position of that Node2D which will be modified on editing, Which will cause modified .tscn scene file when I changed nothing of my scene at all, then Git will blame me to commit changed position of Node2D,

Yes, In short I’m mixing tool script and in-game script in one GDScript file, therefore I need to determine the script is running on editor or not, as same as Question title says.

Is there an way to detect whether a script is running on the editor or on a exported game? Thanks a lot!

[1] which is actually CanvasLayer but That’s not important in this case

:bust_in_silhouette: Reply From: Kamil Lewan

Node.get_tree().is_editor_hint()?

Wow! Thank you! Why I couldn’t find it?!

Ch. | 2017-06-25 20:17

I had problem with it too. Just “editor hint” name is a bit confusing for me as non english-native speaker. GL in codin`.

Kamil Lewan | 2017-06-25 21:04

Invalid call. Nonexistent function ‘is_editor_hint’ in base ‘SceneTree’.

Aaron Franke | 2020-02-27 06:55

:bust_in_silhouette: Reply From: Robin Arys

Since this is the first search result for people searching for this and this changed in Godot 3.0:

In Godot 2: Node.get_tree().is_editor_hint()
In Godot 3: Engine.is_editor_hint()

Thank you for information! I think therer’s a little problem in your article. Can you surround code parts of your articles by `` so _ does not converts into italic style syntax?

Ch. | 2017-11-07 11:11

I’ve fixed it! Sorry it took me this long, I never received an e-mail and just found my own answer when searching for the exact function name :stuck_out_tongue:

Robin Arys | 2019-06-19 08:12

Engine.editor_hint is enough. Engine.is_editor_hint() is the getter of it.

MintSoda | 2021-02-03 02:11