# Can I use multiple collectors in tk-multi-publish2?

**URL:** <https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286>\
**Category:** Pipeline Integrations\
**Created:** [July 29, 2019, 5:02am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286 "2019-07-29T05:02:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt\_ce](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@matt\_ce](https://community.shotgridsoftware.com/u/matt_ce)\
**Post date:** [July 29, 2019, 5:02am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/1 "2019-07-29T05:02:50Z")

</div>

Hi,

I’m looking to implement a Maya Alembic camera publish option in tk-multi-publish2. I watched the tutorial [here](https://www.youtube.com/watch?v=pH4mylrnktY) which was quite helpful.

One thing I’ve noticed though, is that while I can have multiple publish plugin hooks for various purposes (eg. publish\_camera.py and publish\_shader\_network.py [here](https://github.com/shotgunsoftware/tk-config-default2/tree/pipeline_tutorial/hooks/tk-multi-publish2/maya)), it seems that there can only be one collector.py.

I attempted adding more than one to the tk-multi-publish2 config as below, but it seems like the multiple paths override each other.

```
settings.tk-multi-publish2.maya.shot_step:
  collector: "{self}/collector.py:{engine}/tk-multi-publish2/basic/collector.py:{config}/tk-multi-publish2/maya/collector_mesh.py:{config}/tk-multi-publish2/maya/collector_camera.py"

```

(in this case, only collector\_camera.py seems to be run)

I’d love to be able to avoid copying and pasting whole files to my config, since it means that I would miss any updates that are made to the default collector.py, and it’s just extra stuff that I need to maintain. In a perfect world it would be great if SGTK provided some common collector classes in the default tk-multi-publish2 that I could subclass into small modular collector plugins without duplicated code.

Is this correct, or maybe I’m doing something wrong?

cheers

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [July 29, 2019, 8:07am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/4 "2019-07-29T08:07:44Z")

</div>

Hey Matt

Welcome to the forums!!

In a way, you’re correct in that you can only have one collector per Publish2 settings block, unlike the plugins where you can list multiple. However, you can use inheritance to subclass the base collector plugin.

When setting the hook paths you can define a chain of inheritance by separating the paths using `:`.  
In your example, the order of inheritance is (from base to subclasses)

1. The collector from the publish2 app (`{self}/collector.py`).
2. Then you have the engine’s implementation of the collector `{engine}/tk-multi-publish2/basic/collector.py`
3. Then your mesh collector `{config}/tk-multi-publish2/maya/collector_mesh.py`
4. And finally your `{config}/tk-multi-publish2/maya/collector_camera.py`

So in this situation, the `collector_camera.py` needs to ensure that it calls `super` per overridden method so that the `collector_mesh.py` method gets called, and likewise, that needs to call super if you want the engine’s implementation of the hook called.

The `tk-maya` implementation of the collector does this for the settings property:

> <https://github.com/shotgunsoftware/tk-maya/blob/master/hooks/tk-multi-publish2/basic/collector.py#L47>

Hopefully that helps?

Thanks  
Phil

---

<div class="post-metadata">

**Author:** ![matt\_ce](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@matt\_ce](https://community.shotgridsoftware.com/u/matt_ce)\
**Post date:** [July 30, 2019, 2:29am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/5 "2019-07-30T02:29:28Z")

</div>

Hi Phil, thanks!

I did see that before but I assumed that `sgtk.get_hook_baseclass()` would just get the default class defined by the plugin but I just tested it out then and it does what I want!

It wasn’t clear to me before but after looking in the [Hook documentation](https://developer.shotgunsoftware.com/tk-core/core.html#sgtk.Hook) I think I understand it now, the order of inheritance of hooks is defined by the environment config .yml, and the base class retrieved by `sgtk.get_hook_baseclass()` becomes whatever is the hook class that’s defined in the previous file in the .yml ‘collector:’ path list.

Is this right?

thanks

---

<div class="post-metadata">

**Author:** ![matt\_ce](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@matt\_ce](https://community.shotgridsoftware.com/u/matt_ce)\
**Post date:** [July 30, 2019, 7:17am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/6 "2019-07-30T07:17:42Z")

</div>

I think I have this working quite happily now, with _much_ less code to maintain! 🙂

I did have to do a little bit of extra work to find the correct `parent_item` to add my camera item to in `process_current_session()`

```
def process_current_session(self, settings, parent_item):
    super(MayaCameraCollector, self).process_current_session(settings, parent_item)

    # find the maya session item to attach to
    session_item = next((item for item in parent_item.descendants if item.type_spec == 'maya.session'), None)
    if session_item == None:
   	    return

    self._collect_cameras(session_item)

```

It might be nice if the default `process_current_session()` inside tk-maya’s MayaSessionCollector returned the item so that subclasses could continue attaching to it? Is there any recommended way to make small requests like this? A PR against the Shotgun Toolkit github repo?

thanks again

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [July 30, 2019, 10:37am UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/7 "2019-07-30T10:37:42Z")

</div>

> [@matt\_ce](#):
>
> It wasn’t clear to me before but after looking in the [Hook documentation](https://developer.shotgunsoftware.com/tk-core/core.html#sgtk.Hook) I think I understand it now,

We are looking into putting a guide together to compliment the reference documentation, so hopefully, this will make it clearer to others in the future. And yes your understanding is correct!

> [@matt\_ce](#):
>
> It might be nice if the default `process_current_session()` inside tk-maya’s MayaSessionCollector returned the item

I’ve popped a suggestion into our product team on your behalf, and of course your more than welcome to submit a pull request. However, I’m not sure my self how much that would help, the reason being is that the `process_current_session` method could create and link multiple items to the parent item, and those items, in turn, could have child items, so you would need to return back either a dictionary or perhaps a flat list of items, which you can essentially access through the `parent_item.descendants`.

---

<div class="post-metadata">

**Author:** ![johnnyzxt](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/johnnyzxt/32/2031_2.png) [@johnnyzxt](https://community.shotgridsoftware.com/u/johnnyzxt)\
**Post date:** [July 11, 2022, 6:16pm UTC](https://community.shotgridsoftware.com/t/can-i-use-multiple-collectors-in-tk-multi-publish2/286/9 "2022-07-11T18:16:21Z")

</div>

> [@matt\_ce](#):
>
> ```auto
> session_item = next((item for item in parent_item.descendants if item.type_spec == 'maya.session'), None)
> if session_item == None:
> return
> 
> self._collect_cameras(session_item)
> 
> ```

That’s great, Thanks a lot, I watched the same tutorials, and have same questions about collector inheritance method.
