|
8 | 8 | #include "Runtime/AssetRegistry/Public/AssetRegistryModule.h" |
9 | 9 | #include "Kismet2/KismetEditorUtilities.h" |
10 | 10 | #include "Editor/ContentBrowser/Public/ContentBrowserModule.h" |
11 | | - |
| 11 | +#include "Editor/UnrealEd/Public/PackageTools.h" |
12 | 12 | #include "UnrealEd.h" |
13 | 13 | #include "FbxMeshUtils.h" |
14 | 14 | #include "Kismet2/BlueprintEditorUtils.h" |
@@ -588,12 +588,41 @@ PyObject *py_unreal_engine_find_asset(PyObject * self, PyObject * args) |
588 | 588 | FAssetData asset = AssetRegistryModule.Get().GetAssetByObjectPath(UTF8_TO_TCHAR(path)); |
589 | 589 | if (!asset.IsValid()) |
590 | 590 | { |
591 | | - Py_INCREF(Py_None); |
592 | | - return Py_None; |
| 591 | + Py_RETURN_NONE; |
593 | 592 | } |
594 | 593 | Py_RETURN_UOBJECT(asset.GetAsset()); |
595 | 594 | } |
596 | 595 |
|
| 596 | +PyObject *py_unreal_engine_create_asset(PyObject * self, PyObject * args) |
| 597 | +{ |
| 598 | + char *asset_name; |
| 599 | + char *package_path; |
| 600 | + PyObject *py_class; |
| 601 | + PyObject *py_factory; |
| 602 | + |
| 603 | + if (!PyArg_ParseTuple(args, "ssOO:create_asset", &asset_name, &package_path, &py_class, &py_factory)) |
| 604 | + { |
| 605 | + return nullptr; |
| 606 | + } |
| 607 | + |
| 608 | + if (!GEditor) |
| 609 | + return PyErr_Format(PyExc_Exception, "no GEditor found"); |
| 610 | + |
| 611 | + UClass *uclass = ue_py_check_type<UClass>(py_class); |
| 612 | + if (!uclass) |
| 613 | + return PyErr_Format(PyExc_Exception, "argument is not a UClass"); |
| 614 | + |
| 615 | + UFactory *factory = ue_py_check_type<UFactory>(py_factory); |
| 616 | + if (!factory) |
| 617 | + return PyErr_Format(PyExc_Exception, "argument is not a UFactory"); |
| 618 | + |
| 619 | + FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools"); |
| 620 | + UObject *uobject = AssetToolsModule.Get().CreateAsset(FString(UTF8_TO_TCHAR(asset_name)), FString(UTF8_TO_TCHAR(package_path)), uclass, factory); |
| 621 | + if (!uobject) |
| 622 | + return PyErr_Format(PyExc_Exception, "unable to create asset"); |
| 623 | + Py_RETURN_UOBJECT(uobject); |
| 624 | +} |
| 625 | + |
597 | 626 | PyObject *py_unreal_engine_get_asset_referencers(PyObject * self, PyObject * args) |
598 | 627 | { |
599 | 628 | char *path; |
@@ -1882,18 +1911,25 @@ PyObject *py_ue_factory_create_new(ue_PyUObject *self, PyObject * args) |
1882 | 1911 | if (!factory) |
1883 | 1912 | return PyErr_Format(PyExc_Exception, "uobject is not a Factory"); |
1884 | 1913 |
|
1885 | | - UPackage *outer = CreatePackage(nullptr, UTF8_TO_TCHAR(name)); |
1886 | | - if (!outer) |
1887 | | - return PyErr_Format(PyExc_Exception, "unable to create package"); |
1888 | | - |
1889 | | - UClass *u_class = factory->GetSupportedClass(); |
1890 | | - |
1891 | 1914 | char *obj_name = strrchr(name, '/') + 1; |
1892 | 1915 | if (strlen(obj_name) < 1) |
1893 | 1916 | { |
1894 | 1917 | return PyErr_Format(PyExc_Exception, "invalid object name"); |
1895 | 1918 | } |
1896 | 1919 |
|
| 1920 | + FString PackageName = PackageTools::SanitizePackageName(FString(UTF8_TO_TCHAR(name)) + TEXT("/") + FString(UTF8_TO_TCHAR(obj_name))); |
| 1921 | + |
| 1922 | + UPackage *outer = CreatePackage(nullptr, *PackageName); |
| 1923 | + if (!outer) |
| 1924 | + return PyErr_Format(PyExc_Exception, "unable to create package"); |
| 1925 | + |
| 1926 | + TArray<UPackage *> TopLevelPackages; |
| 1927 | + TopLevelPackages.Add(outer); |
| 1928 | + if (!PackageTools::HandleFullyLoadingPackages(TopLevelPackages, FText::FromString("Create a new object"))) |
| 1929 | + return PyErr_Format(PyExc_Exception, "unable to fully load package"); |
| 1930 | + |
| 1931 | + UClass *u_class = factory->GetSupportedClass(); |
| 1932 | + |
1897 | 1933 | // avoid duplicates |
1898 | 1934 | if (u_class->IsChildOf<UBlueprint>()) |
1899 | 1935 | { |
@@ -1982,7 +2018,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args) |
1982 | 2018 | if (!PyArg_ParseTuple(args, "Os|O:add_level_to_world", &py_world, &name, &py_bool)) |
1983 | 2019 | { |
1984 | 2020 | return NULL; |
1985 | | -} |
| 2021 | + } |
1986 | 2022 |
|
1987 | 2023 | UWorld *u_world = ue_py_check_type<UWorld>(py_world); |
1988 | 2024 | if (!u_world) |
@@ -2016,7 +2052,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args) |
2016 | 2052 | #endif |
2017 | 2053 |
|
2018 | 2054 | Py_RETURN_UOBJECT(level_streaming); |
2019 | | - } |
| 2055 | +} |
2020 | 2056 |
|
2021 | 2057 | PyObject *py_unreal_engine_move_selected_actors_to_level(PyObject *self, PyObject * args) |
2022 | 2058 | { |
@@ -2521,7 +2557,7 @@ PyObject *py_unreal_engine_export_assets(PyObject * self, PyObject * args) |
2521 | 2557 | if (!py_iter) |
2522 | 2558 | { |
2523 | 2559 | return PyErr_Format(PyExc_Exception, "argument is not an iterable of UObject"); |
2524 | | -} |
| 2560 | + } |
2525 | 2561 |
|
2526 | 2562 | while (PyObject *py_item = PyIter_Next(py_iter)) |
2527 | 2563 | { |
|
0 commit comments