Create_on_instance() question when using OS.get_executable_path()

Hi, I was reading the documentation for the method OS.get_executable_path() because I’m writing this function:

static func _directory_exist_on_executable_path(directory_path: String) -> Error:
	#if OS.get_name() == "macOS":
		#OS.create_instance()
	var real_path = OS.get_executable_path().get_base_dir().path_join(directory_path)
	
	var directory = DirAccess.open(real_path)
	
	if directory == null:
		return DirAccess.get_open_error()
	
	return OK

So my question it’s not about it not working since it does what I do but I have seen the next warning in documentation and I don’t quite understand it, how should I do it in macOS ?

String get_executable_path() const

Returns the path to the current engine executable.

Note: On macOS, always use create_instance() instead of relying on executable path.

1 Like

I’ve not tested this but I thin that’s because on macOS the exported .app file is just a folder structure that the OS treats differently so OS.get_executable_path() may return you something like .../my_game.app/Contents/MacOS or something like that which may cause some issues if you try to launch the executable that’s inside that folder.

1 Like

Thanks for the reply, I don’t have a Mac around, I will have to test it with someone else’s but I ended with this code:

static func _directory_exist_on_executable_path(directory_path: String) -> Error:
	var os_instance := 0
	
	if OS.get_name() == "macOS":
		os_instance = OS.create_instance([])
		
		if os_instance == -1:
			return ERR_CANT_CREATE
		
	var real_path = OS.get_executable_path().get_base_dir().path_join(directory_path)
	var directory = DirAccess.open(real_path)
	
	OS.kill(os_instance)
	
	if directory == null:
		return DirAccess.get_open_error()
	
	return OK

OS.create_instance() creates a new Godot instance (launches godot with the parameters you pass). It has nothing to do with directories.

1 Like

You are absolutely right, create an instance just to check a directory path makes no sense at all.

I’ll leave it here for now since it doesn’t block me in anything although I still have the mystery of create_instance and how to apply it exactly for mac.