TRASH_StaticMeshComponent interfering with loop

Hi,
i have the same issue, i found a workaround
you need to store the path of the meshComponent and on each loop you reload the object
it’s append when i want to update an meshcomponent inside a BluePrint
always when i use set_editor_property all the list is TRASHED :wink:

first i loop to save all data

   def getSelectedActorData(self):
        acorList = []
        listActors =  self.UUtils.list_selected_actor()


        for item in listActors:
            # list of actorData

            # ActorData contain all information to assign the material
            # Label of Actor
            # Path = Level path include Blueprint
            # type = static or skeletal mesh
            # mesh = mesh or Skeletal
            #
            actorData = {}

            asset_class = item.get_class()
            #class_name = self.system_lib.get_class_display_name(asset_class)
            actor_label = item.get_actor_label()
            actorPath = self.getPathActor(item)

            actorData['label'] = actor_label
            actorData['name'] = item.get_name()
            actorData['path'] = actorPath

            if (self.isBluprintActor(item)):
                # print('------------------BLUE PRINT----------------')
                listComp = item.get_components_by_class(unreal.MeshComponent)

                for SM_Actor in listComp:

                    if SM_Actor == None:
                        continue

                    typeOk = False
                    asset_class_bp = SM_Actor.get_class()
                    class_name_bp = self.system_lib.get_class_display_name(asset_class_bp)
                    if class_name_bp == 'SkeletalMeshComponent':
                        # print('---------------------- Skeletal BP--------------')
                        typeOk = True
                        actorData['type'] = 'SkeletalMeshComponent'
                        actorData['mesh'] = SM_Actor.get_editor_property("skeletal_mesh")

                        # print(SM_Actor.get_parent_components())

                    if class_name_bp == 'StaticMeshComponent':
                        # print('---------------------- Static mesh BP --------------')
                        typeOk = True
                        actorData['type'] = 'StaticMeshComponent'
                        actorData['mesh'] = SM_Actor.get_editor_property("static_mesh")
                        # print(SM_Actor.get_materials())
                        # print(SM_Actor.get_attach_parent())

                    # We saveData blue print
                    if typeOk:
                        if actorData['mesh'] == None:
                            continue

                        fileNameImport = actorData['mesh'].get_editor_property("asset_import_data").get_first_filename()
                        fileNameImport = unreal.Paths.get_base_filename(fileNameImport)

                        actorData['fileNameImport'] = fileNameImport
                        actorData['meshComponent'] = SM_Actor
                        actorData['meshComponentPath'] = SM_Actor.get_path_name()
                        actorData['label'] = SM_Actor.get_name()
                        actorData['name'] = SM_Actor.get_name()
                        actorData['name'] = actorData['name'].replace('[','')
                        actorData['name'] = actorData['name'].replace(']','')
                        actorData['name'] = actorData['name'].replace(':','')
                        actorData['path'] = unreal.Paths.combine([actorPath, self.getPathBluePrintAsset(SM_Actor)])
                        actorData['nameAsset'] = actorData['mesh'].get_name()
                        actorData['pathAsset'] = actorData['mesh'].get_path_name()

                        # print(actorData['label'])
                        # print(actorData['path'])
                        acorList.append(actorData.copy())

            else:
                SM_Actor = item.get_component_by_class(unreal.MeshComponent)
                if SM_Actor == None:
                    continue
                typeOk = False
                asset_class_bp = SM_Actor.get_class()
                class_name_bp = self.system_lib.get_class_display_name(asset_class_bp)
                if class_name_bp == 'SkeletalMeshComponent':
                    # print('---------------------- Skeletal --------------')
                    typeOk = True
                    actorData['type'] = 'SkeletalMeshComponent'
                    actorData['mesh'] = SM_Actor.get_editor_property("skeletal_mesh")

                    # print(SM_Actor.get_parent_components())

                if class_name_bp == 'StaticMeshComponent':
                    # print('---------------------- Static mesh  --------------')
                    typeOk = True
                    actorData['type'] = 'StaticMeshComponent'
                    actorData['mesh'] = SM_Actor.get_editor_property("static_mesh")
                    # print(SM_Actor.get_materials())
                    # print(SM_Actor.get_attach_parent())

                # We saveData blue print
                if typeOk:
                    if actorData['mesh'] == None:
                        continue

                    fileNameImport = actorData['mesh'].get_editor_property("asset_import_data").get_first_filename()
                    fileNameImport = unreal.Paths.get_base_filename(fileNameImport)

                    actorData['name'] = actorData['name'].replace('[', '')
                    actorData['name'] = actorData['name'].replace(']', '')
                    actorData['name'] = actorData['name'].replace(':', '')

                    actorData['meshComponent'] = SM_Actor
                    actorData['meshComponentPath'] = SM_Actor.get_path_name()
                    actorData['fileNameImport'] = fileNameImport
                    actorData['nameAsset'] = actorData['mesh'].get_name()
                    actorData['pathAsset'] = actorData['mesh'].get_path_name()

                    acorList.append(actorData.copy())

        return acorList

after on my program i reload on each loop my actor

#TO AVOID TRASH component we reload the component on each loop
actor = unreal.AssetRegistryHelpers.get_asset_registry().get_asset_by_object_path(actorData['meshComponentPath']).get_asset()

to detect blueprint i found this maybe is a better way

 def isBluprintActor(self,actor):
        asset_class = actor.get_class().get_class()
        class_name = self.system_lib.get_class_display_name(asset_class)
        if class_name == 'BlueprintGeneratedClass':
            return True
        else:
            return False

hope it’s help :slight_smile:

1 Like