[Python] How to get the 'Data Source Folder' path?

In order to get a given asset’s source path, I’m doing:

loaded_asset.get_editor_property('asset_import_data').get_first_filename()

This works fine, but I’d like to be able to get this path as a relative one, using the “Data Source Folder” as a root.

The “Data Source Folder” option is in “Editor Preferences > General > Miscellaneous > Import > Data Source Folder”.
Is such an information accessible by script?

You can do this

@unreal.uclass()
class EditorUtility(unreal.GlobalEditorUtilityBase):
    _instance = None

    @classmethod
    def get(cls):
        if not EditorUtility._instance:
            EditorUtility._instance = EditorUtility()
        return EditorUtility._instance


def get_data_source_folder():
    """Get the data source folder for the project.

    :raises: RuntimeError if the data source folder is not set
    :return:
    """
    settings = EditorUtility.get().get_editor_user_settings()
    data_source_folder = settings.get_editor_property("data_source_folder")
    if not data_source_folder or not data_source_folder.path:
        raise RuntimeError(
            "No Data Source Folder set. Set the Data Source Folder in "
            "Editor Preferences > Miscellaneous > Import > Data Source Folder"
        )
    return data_source_folder.path
1 Like