Download

Return an array of arrays in python script

Anyone know how to return an array of arrays from a python script? I know that the only way to do this in BP is to make a custom struct/class that has an array inside it but how to approach it in python? I tried

    import unreal as UE
UE.uclass()
class GroupedMeshes:
    MeshGroups = UE.Array(UE.StaticMeshActor)

@UE.uclass()
class BPFunctionLibrary(UE.BlueprintFunctionLibrary):
    @UE.ufunction(ret = UE.Array(GroupedMeshes), params =  [UE.World], static = True, meta=dict(Category="PythonScript"))
    def getStaticMeshes(MyLevel):
        return UE.Array(GroupedMeshes)

but that leaves me with
LogPython: Error: @UE.ufunction(ret = UE.Array(GroupedMeshes))
LogPython: Error: TypeError: Array: ‘type’ (classobj) must be a type
inheriting from StructBase or Actor crashes the editor

import unreal

def get_static_mesh_actors(current_world):
    static_mesh_actors = []
    for actor in unreal.ActorIterator(current_world):
        if actor.get_class() == unreal.StaticMeshActor().get_class():
            static_mesh_actors.append(actor)
    return static_mesh_actors

I’m sure there’s a better way to check if an actor is a Static Mesh, but all of mine start with “SM_”, so I usually use actor.get_actor_label() and check if it startswith that.

Hope this helps

Yes that returns an array of static meshes, but I want to return an array of arrays of static meshes