@@ -294,6 +294,13 @@ PyObject *py_ue_get_full_name(ue_PyUObject *self, PyObject * args) {
294294 return PyUnicode_FromString (TCHAR_TO_UTF8 (*(self->ue_object ->GetFullName ())));
295295}
296296
297+ PyObject *py_ue_get_path_name (ue_PyUObject *self, PyObject * args) {
298+
299+ ue_py_check (self);
300+
301+ return PyUnicode_FromString (TCHAR_TO_UTF8 (*(self->ue_object ->GetPathName ())));
302+ }
303+
297304PyObject *py_ue_set_property (ue_PyUObject *self, PyObject * args) {
298305
299306 ue_py_check (self);
@@ -735,42 +742,71 @@ PyObject *py_ue_get_cdo(ue_PyUObject * self, PyObject * args) {
735742#if WITH_EDITOR
736743PyObject *py_ue_save_package (ue_PyUObject * self, PyObject * args) {
737744
745+ /*
746+
747+ Here we have the following cases to manage:
748+
749+ calling on a UObject without an outer
750+ calling on a UObject with an outer
751+ calling on a UObject with an outer and a name arg
752+
753+ */
754+
738755 ue_py_check (self);
739756
757+ bool has_package = false ;
758+
740759 char *name = nullptr ;
741760 UPackage *package = nullptr ;
742761 if (!PyArg_ParseTuple (args, " |s:save_package" , &name)) {
743762 return NULL ;
744763 }
745764
746- if ( self->ue_object ->IsA <UPackage>())
747- package = (UPackage *) self->ue_object ;
765+ UObject *outer = self->ue_object ->GetOuter ();
766+ UObject *u_object = self->ue_object ;
748767
749- if (!package) {
750- if (!name)
751- return NULL ;
768+ if (outer && outer->IsA <UPackage>() && outer != GetTransientPackage ()) {
769+ package = (UPackage *)outer;
770+ has_package = true ;
771+ }
772+
773+ if (!package || name) {
774+ if (!name) {
775+ return PyErr_Format (PyExc_Exception, " the object has no associated package, please specify a name" );
776+ }
752777 package = CreatePackage (nullptr , UTF8_TO_TCHAR (name));
753778 if (!package)
754779 return PyErr_Format (PyExc_Exception, " unable to create package" );
755- }
756-
757- FString filename = FPackageName::LongPackageNameToFilename (UTF8_TO_TCHAR (name), FPackageName::GetAssetPackageExtension ());
758-
759- if (!self->ue_object ->Rename (*(self->ue_object ->GetName ()), package)) {
760- return PyErr_Format (PyExc_Exception, " unable to set object outer to package" );
780+ package->FileName = *FPackageName::LongPackageNameToFilename (UTF8_TO_TCHAR (name), FPackageName::GetAssetPackageExtension ());
781+ if (has_package) {
782+ FString split_path;
783+ FString split_filename;
784+ FString split_extension;
785+ FString split_base (UTF8_TO_TCHAR (name));
786+ FPaths::Split (split_base, split_path, split_filename, split_extension);
787+ u_object = DuplicateObject (self->ue_object , package, FName (*split_filename));
788+ }
789+ else {
790+ // move to object into the new package
791+ if (!self->ue_object ->Rename (*(self->ue_object ->GetName ()), package)) {
792+ return PyErr_Format (PyExc_Exception, " unable to set object outer to package" );
793+ }
794+ }
761795 }
762796
763797 package->FullyLoad ();
764798 package->MarkPackageDirty ();
765799
766- if (UPackage::SavePackage (package, self->ue_object , RF_Public | RF_Standalone, *filename)) {
767- FAssetRegistryModule::AssetCreated (self->ue_object );
768- Py_INCREF (Py_True);
769- return Py_True;
800+ if (UPackage::SavePackage (package, u_object, RF_Public | RF_Standalone, *package->FileName .ToString ())) {
801+ FAssetRegistryModule::AssetCreated (u_object);
802+ ue_PyUObject *ret = ue_get_python_wrapper (u_object);
803+ if (!ret)
804+ return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
805+ Py_INCREF (ret);
806+ return (PyObject *)ret;
770807 }
771808
772- Py_INCREF (Py_False);
773- return Py_False;
809+ return PyErr_Format (PyExc_Exception, " unable to save package" );
774810}
775811
776812PyObject *py_ue_asset_can_reimport (ue_PyUObject * self, PyObject * args) {
0 commit comments