Find meshes recursive I have a root element with some objects that could be a variable level of depth, but it mostly just goes 2-3 levels deep.
I am trying to get all the meshes within the root object but doesn't seem to be able to reach them?
I also admit I am not good at this recursive thing.
structure:

function:
def findMeshObjectsRecursive(searchObject, levels=10, meshList=None):
    def recurse(searchObject, parent, depth, meshList):
        if(meshList == None):
            meshList = []       
        if(searchObject.type == 'MESH'):
            return searchObject
        if depth &gt; levels: 
            print('return list 1')
            return meshList
        print(&quot;  &quot; * depth, searchObject.name)

        for child in searchObject.children:
            meshList.append(recurse(child, searchObject,  depth + 1, meshList))
        return meshList

    try: return recurse(searchObject, searchObject.parent, 0, meshList)
    except Exception:
        traceback.print_exc()
        return meshList

output
 mrotxhi_1
 EMPTY
 shaftxhi_1
 EMPTY
 trotxhi_1
 EMPTY

I would expect it to print more objects, because later in the code I add blend modes and transparencies to these objects but it is not working now because it cannot find any MESH type objects... I previously tested this with a different structure that did work.
More Python thing than Blender's one, but you can:
import bpy

def find_meshes_recursive( root, levels=10, meshes=None ):
    # Initialize the result once
    if meshes is None:
        meshes = []

    def recurse( parent, result, level, levels ):
        # Does nothing if level is reached
        if level &lt; levels:
            # Keeps meshes
            if parent.type == 'MESH':
                result.append(parent)
            # Look over children at next level
            for child in parent.children:
                recurse( child, result, level + 1, levels )
    
    recurse( root, meshes, 0, levels )
    return meshes

root = bpy.context.object

meshes = find_meshes_recursive(root, levels = 10)
print(meshes)

Note that you can also do it in non recursive way:
def find_meshes(root, levels=10, meshes=None):
    meshes = [] if meshes is None else meshes
    
    parents = [root]
    while levels &gt; 0 and parents:
        meshes.extend([obj for obj in parents if obj.type == 'MESH'])
        parents = [child for obj in parents for child in obj.children]
        levels -= 1
        
    return meshes