Is it yet possible to add nodes to an Editor Graph? Like the people above, I think it would have value to automate the construction of Blueprint hierarchies.
My solution for BP for each mesh asset, withou static mesh component:
import unreal
package_path = '/Game/PLATFORMER_StylizedCubeWorld_Vol1/Models/Background'
# Get all assets in the folder
all_assets = unreal.EditorAssetLibrary.list_assets(package_path)
# Extract and print the names of the assets
for asset_data in all_assets:
asset_name = asset_data.rsplit(".", 1)[-1]
factory = unreal.BlueprintFactory()
factory.set_editor_property("ParentClass", unreal.Actor)
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
my_new_asset = asset_tools.create_asset(asset_name + "_BP", package_path, None, factory)
unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset)
Hello there! Trying to do something similar with python with no good results. Honestly I canât grasp the logic very well. Can someone help please? Going back to the original question I would like to add my StaticMesh inside my BP.
There is a way to add static mesh components to a BP actor class created by Python, one can use the âunreal.SubobjectDataBlueprintFunctionLibrary.get_data/get_objectâ functions. I include a function which creates BP actor and assigns static meshes based on the code by
@Havard_stardust
def createBP(asset_name='myNewBPActorClass',
package_path='/Game',
mesh_asset_path='/Engine/BasicShapes/Cube',
material_asset_path='/Engine/BasicShapes/BasicShapeMaterial_Inst',
component_prefix='Piece',
component_width=110,
inst_pos=unreal.Vector(-4000, -450, 50),
inst_label='custom_BP'):
'''create an instance of a new BP class with 30 static (Cube) mesh components
asset_name: string, name of the new BP class
package_path: string, the folder/path in the content browser to store the new BP
mesh_asset_path: string, path of the static mesh asset in UE5 content browser
material_asset_path: string, path (in the UE5 content browser) of the material
assinged to static mesh components in the new BP actor
component_prefix: string, prefix of the name of static mesh components in the new BP actor
component_width: integer > 0, the (bounding box) width of the static mesh components in the BP
inst_pos: unreal.Vector, position of the new BP actor instance in the level
inst_label: string, name/label of the instance of the newly created BP actor
On Exit:
creates a new BP class, and itialises an instance in the Level
'''
# the number of static mesh components in the BP actor
number_of_componets = 30
# create a new BP class asset
factory = unreal.BlueprintFactory()
factory.set_editor_property("ParentClass", unreal.Actor)
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
my_new_asset = asset_tools.create_asset(asset_name, package_path, None, factory)
unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset)
# get the root data handle
subsystem = unreal.get_engine_subsystem(unreal.SubobjectDataSubsystem)
data_handles = subsystem.k2_gather_subobject_data_for_blueprint(my_new_asset)
# we need the value of the root data handle which
# seems to be the data handle with index 0!
root_data_handle = data_handles[0]
# our new asset is the new BP actor class
bp_actor = my_new_asset
# static mesh asset to assign to static mesh components of BP actor
static_mesh_asset = unreal.load_asset(mesh_asset_path)
# load the test material
testMat = unreal.EditorAssetLibrary.find_asset_data(material_asset_path).get_asset()
# create 30 static mesh component subobjects
for x in range(0, number_of_componets):
# unreal.StaticMeshComponent class alias
staticmesh = unreal.StaticMeshComponent
#add new component
sub_handle, fail_reson = subsystem.add_new_subobject(
params=unreal.AddNewSubobjectParams(
parent_handle=root_data_handle,
new_class=staticmesh,
blueprint_context=bp_actor))
subsystem.rename_subobject(handle=sub_handle, new_name=unreal.Text(component_prefix + str(x)))
data = unreal.SubobjectDataBlueprintFunctionLibrary.get_data(sub_handle) # get data
data_obj = unreal.SubobjectDataBlueprintFunctionLibrary.get_object(data) # get data object
# print(data_obj) # this is the actual static_mesh compoment of the BP actor
data_obj.set_editor_property('static_mesh', static_mesh_asset)
data_obj.set_relative_location(unreal.Vector(x * component_width, 0.0, 0.0), False, False)
data_obj.set_material(0, testMat)
# save the new BP actor asset
unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset)
# create a new instance in the editor
custom_bp_class = unreal.EditorAssetLibrary.load_blueprint_class(package_path+'/'+asset_name)
eaSub = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
new_custom_actor = eaSub.spawn_actor_from_class(custom_bp_class,
inst_pos,
unreal.Rotator(0, 0, 0))
new_custom_actor.set_actor_label(inst_label)
unreal.log(f'New BP actor instance --> {new_custom_actor}.')