+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

+8 votes
Best answer

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

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

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

by (11,255 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
    else:
        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,437 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"):
      get_tree().change_scene_to(nextScene)

You can check more options. Awesome stuff:
https://docs.godotengine.org/en/stable/getting_started/workflow/export/feature_tags.html

by (300 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.