What is a Hook and what is it for?

This is a question that we get asked fairly often:

The difference between a hook and a normal function is not clear to me, does the hooks execute on a different thread or something like that? What is the benefit?

Follow

1 Comments

  • 1
    Avatar
    Manne Öhrström

    Tank Apps, Engines and Frameworks all have configuration settings. These settings can be a range of different things, all the way from simple flags to say "enable debug output" to complex settings like file system locations (using our template system) or shotgun fields. 

    Apps are authored to be as generic as possible so that they can plug into many different workflows. The settings makes this possible. For example, a publish app needs to know where to write its published files to. The app therefore exposes a setting where the user can specify where those files can go. 

    In some cases, there may be the need for more advanced configuration. This is where hooks come into play. Imagine for example a breakdown app in Maya, which scans the scene for referenced material and then determines which of these references are out of date. In this case, the app needs to contain some sort of logic that scans the current scene and then returns a list of file paths of referenced objects. The app will then look at those paths and determine if they represent an old or an up to date version.

    The scene scanning logic will need to look through the scene for items that have been referenced or imported. The problem is that different studios manage this in different ways; some use custom reference nodes, others store paths in name spaces or using custom attributes. Others use maya referencing or imports etc. The app developer cannot foresee the logic needed to scan the scene.

    This is where a hook comes in. Imagine a hook being like a setting, but instead of returning a value, it is actually a snippet of code that tank will run in order to figure something out. In the case of the breakdown, the hook scans the scene and returns all the file paths it can find in the scene so that the App can display a list in its UI and determine which paths are out of date.

    Like all settings, hooks have default values - these are little python scripts that come bundled with the app and that gets copied into the project when the app gets installed. The default hook for our breakdown app would be looking for maya references and file texture nodes, two well known ways of referencing content into a Maya scene. But a studio needing to customize this further would only need to go in and edit the hook file in order to extend the behaviour - no need to change the main app code.

Please sign in to leave a comment.