Trying to use a DependList as an attribute in a parent COMP’s extension to keep track of instances of certain children COMPs inside it, and I have the list-updating logic (appending and removing items from this DependList) in child’s extension class constructor and destructor. However I’m running into a few problems… Example .toe file is attached.
Here is what’s in the parent’s COMP (named “Base”, with its parent shortcut set as “Base”):
My idea is that when I create or delete any instances of this “Child” COMP, the parent’s “ChildrenList” attribute will be automatically updated. The updating logic is inside each “Children” COMP:
The problems I’m running into are:
(1) A cook dependency is detected when I have the ChildrenList updating logic in Child’s COMP extension class constructor.
(2) When I delete an instance of “Child”, its destructor is called, however line 23 from the above saying it cannot access the parent “Base” COMP using parents shortcut.
My bigger question here is - what’s a better way to update a parent’s DependList attribute when keeping track of certain instances of its children? Any insights are appreciated! ChangeParentDependListWithChildConstructorDestructor.toe (4.5 KB)
Hey @Ivan , in my actual project file I have different groups of COMPs that I’m tracking with different lists. Yeah I can loop through the parent COMP and gather each group every time I need to get them using things like tags - that’s actually what I’m doing currently. But I read about DependList and dependable properties so I’m wondering if there’s a cleaner way to achieve this.
There’s no need to make the lists dependable unless you’re doing things like accessing them in parameters that you want to cause cooks automatically.
That said, if you really need to use dependLists to track operators, you’re much better off storing them as path strings instead of actual operator references.
@Ivan I see. Ultimately the idea is that, OPs in each of these lists are dynamically created and destroyed. When an instance is created/destroyed, other OPs will be created and destroyed somewhere else in the network in response to the status of the instance. So my original thoughts were something like:
child instance created → update parent’s list in child’s constructor → causes other OPs to be created automatically.
child instance is being destroyed → update parent’s list in child’s destructor → causes other OPs to be destroyed automatically.
So in this case, is there a better way to achieve something like this other than getting the lists using things like OP Find or parentCOMP.findChildren()?
Keeping dependLists of OPs that are being created and destroyed is going to cause problems.
Use a regular list if you’re updating it by hand anyway.
Or use a dependList and keep paths in it instead of OPs.
Sounds like you know when things are happening anyway and could create your own callbacks instead of trying to use TD’s dependency system, which is a bit arcane and can have many side effects.
@Ivan Cool cool, thanks for the suggestion! Yeah, also after reading some more on python’s garbage collection, it doesn’t seem like a good idea to do the item removal from the Child’s destructor anyway…