I’m a bit confused about what this hook is for.
I want to run some code before sg_desktop displays the apps. Engine_init isn’t suitable as the app icons can finish displaying before this hook completes, resulting in a crash if a user clicks on an icon prior to the hook completing.
tank_init works as it completes prior to the project UI being displayed.
In tank_init I want to monkey-patch some methods on to the sgtk_instance.
This works for the sg_desktop engine.
eg
in tank_init :-
sgtk_instance.foo = “bar”
in engine_init:-
print(engine.sgtk.foo)
“bar”
The problem is that the foo attribute isn’t accessible when engine_init runs for a dcc engine; eg when I launch nuke, engine.sgtk.foo doesn’t exist.
Is there any way to pass objects from tank_init so they are available in dcc environments?
If not, is there a way to prevent apps from appearing in sg_desktop until the engine_init hook has completed?
When looking into the process of launching a DCC from SG Desktop to my knowledge it looks something like this:
Site PC TK instance initialised, Project icons displayed
Project selected by user
Project PC and TK instance initialised
tk-desktop initialised with commands registered for each tk-multi-launchapp configuration for each DCC making use of this launch method
DCC selected
DCC executed via app launch hook as a subprocess and TK bootstrapped using TANK_CURRENT_PC / startup.py for the specified engine in the new process
To pass information to the new DCC subprocess you’d have to rely on environment variables used in the subprocess spawned from app launch hook or via custom handling with pickled data saved in the app launch hook and then unpickled in the tank_init hook in the DCC subprocess and python interpreter/handler.
On the topic of icons appearing before tk-desktop engine_init, this described behaviour makes sense because this hook runs after the apps initialise and register their commands (icons) with tk-desktop.
Each engine however can implement:
pre_app_init
post_app_init
And tk-desktop makes use of only post_app_init. If you wanted to make changes in this space you’d be looking to customise the engine itself.