+1 vote

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

asked Jan 9 in Engine by AiTechEye (101 points)

2 Answers

+1 vote
Best answer

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.

answered Jan 10 by Adam_S (981 points)
edited Jan 10 by Adam_S

got it, thanks :)

+2 votes

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.

answered Jan 10 by Calinou (6,336 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.