Change property of blueprint asset with python/ Editor Utility

I’m not sure if I used the proper terms in the title, so let me give a simple example what I try to do:
Assume you have n blueprints with AActor as parent. (Basically you created those in the content browser). Every one of these blueprints has a StaticMeshComponent.

As an example I want to enable physics (Simulate Physics = true) for every one of the StaticMeshComponents of those n blueprints.

How do I do that with python or Editor Utility Blueprint? Can someone give an example?

ok after some trying I figured it out.

Here an example python snippet to enable physics and disable start awake for all selected actors. The last thing to figure out is to get all components of type. But for that it probably needs some helper c++ functions.

import unreal

# first, get your blueprint asset by any means you want (here from selected asset)
for a in unreal.EditorUtilityLibrary.get_selected_assets():

    # then get its generated class as string path and load it
    bp_class = unreal.load_object(None, a.generated_class().get_path_name())
    
    # finally get the default object, which is the object from which we can call a function or modify a property
    bp_cdo = unreal.get_default_object(bp_class)

    # Get the static mesh component. This should be the internal name, so you need to change it. 
    static_mesh_component = bp_cdo.get_editor_property("mesh")

    # Enable simulate physics if it's a StaticMeshComponent
    if isinstance(static_mesh_component, unreal.StaticMeshComponent):

        #enable physics
        static_mesh_component.set_simulate_physics(True)

        # disable start awake
        bi = static_mesh_component.body_instance
        bi.set_editor_property("start_awake", False)

        # Save the modified asset
        unreal.EditorAssetLibrary.save_loaded_asset(bp_class)
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.