+3 votes

Suppose I have two nodes like below:

Node2D (with exported ImageTexture)

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

in Engine by (72 points)
edited by

2 Answers

+1 vote
Best answer


by (186 points)
selected by

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

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

Invalid call. Nonexistent function 'iseditorhint' in base 'SceneTree'.

+27 votes

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()

by (74 points)
edited by

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?

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 :P

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.