Set ENV variables using tk-multi-launchapp hook before_app_launch


I’ve recently moved our studio’s SG config from tk_config_default to tk_config_default2; I have to say it was not a trivial task, and I’d like to give special thanks to Philip Scalding for his numerous advice on the support forum.

Now to my question:
In the old config, we had set up our ENV variables using:

It works perfectly fine and it was called from config\env\includes\app_launchers.yml. For example Maya block looks like:

  defer_keyword: ''
  engine: tk-maya
  hook_app_launch: default
  hook_before_app_launch: **'{config}/'**
    version: v0.10.1
    type: app_store
    name: tk-multi-launchapp
  versions: [Maya2018]
  windows_path: '@maya_windows2018'

And the key ‘launch_maya_2018’ was called from inside config\env\project.yml

With the tk_config_default2, where should we put the call to

I assumed the call should go under a maya block in
config\env\includes\settings\tk-multi-launchapp.yml for example:

# app-specific launchapp configurations
# mari
  engine: tk-mari
  linux_path: "@path.linux.mari"
  mac_path: "@path.mac.mari"
  windows_path: ""
  menu_name: Mari
  location: ""

## Maya
  engine: tk-maya
  location: ""
  hook_before_app_launch: "{config}/"

But that doesn’t work.

My other option was to use includes/settings/tk-maya.yml but it doesn’t have a block for tk-multi-launchapp

Btw, I have added engine_name arg to in the execute method.


EDIT: Ignore that message, Philip gave the solution down there

Hi there,
I am currently searching for this too, it seems from your post you forgot to add tk-multi-launchapp to tk-maya.yml:

:diamonds: copy to {config}/tk-multi-launchapp/
:diamonds: add those lines to tk-multi-launchapp.yml:
engine: tk-maya
location: ""
hook_before_app_launch: "{config}/tk-multi-launchapp/"

:diamonds: add tk-multi-launchapp: "" to the apps part of your different environments in tk-maya.yml

Please note that I’m not exactly sure I’m right there as this gives me errors when launching SG Desktop, but I think that’s the logic here.

TankError: Include error. Could not resolve references for L:\_tech\sgtk_sandbox\config\env\.\includes\settings\tk-maya.yml: Undefined Reference!


In the default2 config, the Maya launcher is controlled via the Software entity, as are most of the software we integrate with. So as the software is configured in Shotgun, we have two software generic launch app settings blocks:

(One is specific to the tk-shotgun engine though)

So you would add the hook definition to those two blocks.

Then as you mention, your hook needs to now include the engine_name parameter, as this hook will be called for all software. You can use this value to work out which software is launching.

That should hopefully do it.

1 Like

Hi Philip,
Thanks for the reply. I added hook to those two blocks in tk-multi-launchapp.ym:

# auto discover DCCs for launch
  use_software_entity: true
  hook_before_register_command: "{config}/tk-multi-launchapp/"
  hook_before_app_launch: "{config}/"
  location: ""

# shotgun
  use_software_entity: true
  skip_engine_instances: ["tk-nukestudio"]
  hook_before_register_command: "{config}/tk-multi-launchapp/"
  hook_before_app_launch: "{config}/"
  location: "":

But I get a KeyError for ‘MAYA_MODULE_PATH’:

2019-11-27 12:21:52,282 [   ERROR] [PROXY] Error calling __commands::maya_2018((), {}):
Traceback (most recent call last):
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\app_store\tk-desktop\v2.4.12\python\tk_desktop\", line 164, in _trigger_callback
    callback(*args, **kwargs)
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\core\python\tank\platform\", line 1084, in callback_wrapper
    return callback(*args, **kwargs)
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\app_store\tk-multi-launchapp\v0.10.3\python\tk_multi_launchapp\", line 125, in launch_version
    *args, **kwargs
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\app_store\tk-multi-launchapp\v0.10.3\python\tk_multi_launchapp\", line 354, in _launch_callback
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\app_store\tk-multi-launchapp\v0.10.3\python\tk_multi_launchapp\", line 185, in _launch_app
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\core\python\tank\platform\", line 575, in execute_hook
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\install\core\python\tank\", line 618, in execute_hook_method
    ret_val = hook_method(**kwargs)
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\config\hooks\", line 227, in execute
  File "X:\sgtk_studio\_projects\sg_advprjsetup\shotgun_configuration_dev\config\hooks\", line 260, in env_paths_sanity_check
    for item in os.environ[path_item].split(';'):
  File "C:\Program Files\Shotgun\Python\lib\", line 425, in __getitem__

To be clear this is the same that works fine on any project before DefCon2.

Looking at SG desktop log, there seems to be no args passed to the execute method:

2019-11-27 12:21:52,071 [   DEBUG] [PROXY] Running before app launch hook...
2019-11-27 12:21:52,073 [   DEBUG] [PROXY] >: Resolved hook expression (associated with setting 'hook_before_app_launch'): '{config}/' -> ['X:\\sgtk_studio\\_projects\\sg_advprjsetup\\shotgun_configuration_dev\\install\\app_store\\tk-multi-launchapp\\v0.10.3\\hooks\\', 'X:\\sgtk_studio\\_projects\\sg_advprjsetup\\shotgun_configuration_dev\\config\\hooks\\']
2019-11-27 12:21:52,101 [   DEBUG] [PROXY] app_path >> 
2019-11-27 12:21:52,101 [   DEBUG] [PROXY] app_args >> 
2019-11-27 12:21:52,102 [   DEBUG] [PROXY] version >> 
2019-11-27 12:21:52,104 [   DEBUG] [PROXY] engine_name >>
1 Like

Philip, please ignore my previous post, it’s solved.

For future references, in the legacy we had an if-else to identify maya version that looked like:

 if version == "Maya2018":
        module_path = module_path + os.sep + '2018'

However in DefCon2, version var doesn’t include DCC name so removing “Maya” fixed the problem.


I have a follow up question.
In the old config, I have separate per DCC. For example:

config\hooks\ >>> handles Maya only variables.

In DefCon2, can we continue using separated before_app_launch files per DCC, and how would that work?


Using the software entity approach, you don’t get a separate tk-multi-launchapp settings block per software, so you can only define one hook. That hook, in turn, could import separate python files based upon the engine_name however, so that would be the way around it.

Or alternatively, you could go back to the old method of defining tk-multi-launchapp settings per software.


Using one hook and passing in the engine_name works perfectly. Thanks.