Hello,
I’m currently trying to write a python script that will read through a folder and create “targets”. A target is basically an actor with a plane and a texture. In my folder I have an XML for name and dimensions and then a .dds for the texture. I’m able to import the texture and create a material with it, I’m also able to create the blueprint actor but when I want to create a StaticMeshComponent for the created actor I just can’t seem to find the solution.
I currently use this code to create a blueprint :
# Create an Actor factory
factory = unreal.BlueprintFactory()
factory.set_editor_property("parent_class", unreal.Actor)
# make the blueprint asset
new_asset = ASSET_TOOLS.create_asset("BP_"+asset_name, package_path, None, factory)
if not isinstance(new_asset, unreal.Blueprint):
raise Exception("Failed to create blueprint asset")
Then to add my StaticMeshComponent I’ve tried
# Add staticmeshcomponent to our actor
static_mesh: unreal.StaticMeshComponent = unreal.StaticMeshComponent()
static_mesh.attach_to(new_asset .root_component)
Also :
root_data_handle: unreal.SubobjectDataHandle = subsystem.k2_gather_subobject_data_for_blueprint(context=blueprint)[0]
sub_handle, fail_reason = subsystem.add_new_subobject(
params=unreal.AddNewSubobjectParams(
parent_handle=root_data_handle,
new_class=new_class,
blueprint_context=blueprint))
if not fail_reason.is_empty():
raise Exception("ERROR from sub_object_subsystem.add_new_subobject: {fail_reason}")
subsystem.rename_subobject(handle=sub_handle, new_name=unreal.Text(name))
I don’t get any errors but the component isn’t created.