# Tank\_init confusion

**URL:** <https://community.shotgridsoftware.com/t/tank-init-confusion/19840>\
**Category:** Uncategorized\
**Created:** [February 13, 2025, 10:53am UTC](https://community.shotgridsoftware.com/t/tank-init-confusion/19840 "2025-02-13T10:53:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [February 13, 2025, 10:53am UTC](https://community.shotgridsoftware.com/t/tank-init-confusion/19840/1 "2025-02-13T10:53:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Halil](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/halil/32/4697_2.png) [@Halil](https://community.shotgridsoftware.com/u/Halil)\
**Post date:** [February 14, 2025, 5:55am UTC](https://community.shotgridsoftware.com/t/tank-init-confusion/19840/2 "2025-02-14T05:55:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [February 14, 2025, 11:00am UTC](https://community.shotgridsoftware.com/t/tank-init-confusion/19840/3 "2025-02-14T11:00:07Z")

</div>

Hey Halil,  
Thank you so much for your great post.  
You know what?.. I totally forgot about those new(ish) hooks!
