Hook for switching projects

Is there a hook that gets called when switching projects in desktop?
I need to be able to change environment variables and sys.path before anything else runs.

We have per project python libraries that are managed outside of shotgun. I need the correct project code pathed before my custom engine setup code runs.

When do these core hooks trigger?
It looks like one of them should be where I want mess with sys.path and sys.modules.

engine_init.py (does this trigger before the desktop engine for the project starts?)

The very first core hook that gets triggered is the tank_init, what you are trying to do should work in there since it gets called before sg desktop reads the yaml configs…

(From my personal testing)

1 Like

For anyone else stumbling upon this the context_change.py hook might also be useful.

Full list of hooks can be found here: tk-core/hooks at master · shotgunsoftware/tk-core · GitHub