+4 votes

Is there a way to check if the game is running by the editor or it self?

in Engine by (193 points)

3 Answers

+9 votes
Best answer

You can check for the presence of the standalone feature tag:

if OS.has_feature("standalone"):
    print("Running an exported build.")
    print("Running from the editor.")

Unlike OS.is_debug_build(), it'll evaluate to true even in debug export templates.

by (11,891 points)
selected by
+1 vote

OS.is_debug_build() returns true when running in the editor or a debug build, and returns false in a release build.

Edit: Ignore the rest of this answer and look at Calinou's one.

You could also do something like:

# filename of your godot executable
var godot_exe = "Godot_v3.1.2-stable_win64.exe"

func check_if_exported():
    var path = OS.get_executable_path()
    if godot_exe in path:
        return false
        return true

which returns true in each exported build.
But your Godot's filename and the variable would need to be always equal.

by (1,444 points)
edited by

got it, thanks :)

+3 votes

I use this to skip the intro scene in editor (not to waste time).

func _ready():
   if OS.has_feature("editor"):

You can check more options. Awesome stuff:

by (304 points)
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.