No announcement yet.

Create and edit values in child BP through python

  • Filter
  • Time
  • Show
Clear All
new posts

    Create and edit values in child BP through python

    Good Day,
    I am trying to create a child of a BP through python, searching the documentation and not seeing anything for creation of blueprints or making a child of one. After making it i want it then edit some of the values within it.

    I just got this working, still hardcoded values right now, but it works to generate child bps based on any blueprint class. If you're basing off a C++ class its a bit easier.

    The root class string is achieved from right-clicking the asset and copying reference.

    import unreal as ue
    # New Asset Name
    asset_name = "AwesomeNewAsset"
    # Save Path
    package_path = "/Game/Lush"
    # Derive a Class from a string path
    root_class = '/Game/Lush/Blueprints/Placables/Prop_Base.Prop_Base'
    root_class_generated = root_class + "_C"
    root_class_loaded = ue.EditorAssetLibrary.load_asset(root_class)
    # Derive a BlueprintGeneratedClass from a UBlueprint
    # If you have a C++ class, you can replace all this with just ue.CPPCLASSNAMEHERE
    parent_class = ue.get_default_object(ue.load_object(None, root_class_generated)).get_class()
    # Factory Setup
    factory = ue.BlueprintFactory()
    factory.set_editor_property("ParentClass", parent_class)
    # Get Asset Tools
    asset_tools = ue.AssetToolsHelpers.get_asset_tools()
    # Create Asset
    childBP = asset_tools.create_asset(asset_name, package_path, root_class_loaded.static_class(), factory)
    Daniel Orchard
    Technical Director
    Marketplace | Blog


      Just an extra line of code to above which is helpful. After you have your childBP ref (UBlueprint) you can make it more usable with:
      bp_gc = ue.EditorAssetLibrary.load_blueprint_class(childBP.get_path_name())
      Which will give you the BlueprintGeneratedClass

      Then if you wanted to change data on it, you can get the cdo by:
      bp_cdo = ue.get_default_object(bp_gc)

      Daniel Orchard
      Technical Director
      Marketplace | Blog