How do you call custom methods in nested templates from scripts within the root container?
For example assume method ‘myMethod()’ on template ‘Template B’. Template B is contained within another template, ‘Template A’.
(e.g. Root Container → Template A → Template B).
I can obtain a reference to Template B from the root, but I can not call the method ‘myMethod()’ on that template. Using ‘hasattr’ also shows that the method is not present (it is not a member of ‘Template Holder’ nor ‘Vision Template’).
However, if Template B is not nested within another template I can obtain a reference where the method exists and is callable (even if it is nested inside another component, like a container).
Thoughts on why this is so and how to work around this?
Put whatever script you have into the scripting module section of your project and call it directly from there. I think you probably can drill down and get it eventually by doing .getComponent(0) on the template instance itself to get the actual properties/custom methods you have attached.
But I think a much cleaner way would be to put your script into the script modules and just call it from there instead.
I have yet to find a use case where a custom method on a component is preferable to calling the same script from the project library.