Announcement

Collapse
No announcement yet.

OnConstruction Not Being Run When Creating a New Blueprint From a Custom Actor Class

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    OnConstruction Not Being Run When Creating a New Blueprint From a Custom Actor Class

    I am trying to convert a static mesh asset into a blueprint version of that asset using python and c++. I don't want to spawn this blueprint, just to create it as an asset in the content browser.

    I have created a subclass of Actor in c++ that adds a static mesh component in the constructor and then in the OnConstruction override method attaches a static mesh to that component based on a UProperty that is set in python by modifying the CDO property of the custom parent class.

    The constructor runs, creates the subcomponent and the blueprint is created in the content browser with the editor property set correctly, but the OnConstruction never runs.

    Is there a better way to do this or a way to force the construction script to run?


    Custom Actor Class:

    AMyActorTest::AMyActorTest()
    {
    Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = Root;
    m_Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
    m_Mesh->SetupAttachment(RootComponent);
    }

    void AMyActorTest::OnConstruction()
    {
    if (MyMesh != nullptr)
    {
    m_Mesh->SetStaticMesh(MyMesh);
    }
    RegisterAllComponents();
    }


    Python Creation Script:

    # Modify CDO
    actor = unreal.MyActorTest
    cdo = actor.get_default_object()
    mesh = unreal.load_asset('/Game/couch.couch')
    cdo.set_editor_property("my_mesh", mesh)

    # Create BP
    name = "MESH"
    path = "/Game"
    factory = unreal.BlueprintFactory()
    factory.set_editor_property("ParentClass", unreal.MyActorTest)
    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
    bp_asset = asset_tools.create_asset(name, path, None, factory)
Working...
X