Unreal Engine 1 package system

Posted 2011-05-11

When I began my work on Residual Decay I needed a way to store all new things in one handy archive (like dxt5 compressed textures). The best (and easiest) way out was using native UEngine package system. 

Saving content in UEngine 1 is in fact very easy process. To illustrate the process I'm going to skip serialization. Let's say for example, that we have one native class:

class Something extends Object native;
var string SomeString;

and all we want to do is to apply value to SomeString and save it in separate package. All we got to do is to create UPackage, create object Something apply value to SomeString and save it. Let's do it then:

//package name
FString PkgName = FString(TEXT("OurPackage"));
//creates package
UPackage* NewPkg = UObject::CreatePackage(NULL, *PkgName);
//creates something class we'll going to use to create object
UClass* SomethingClass = UObject::StaticLoadClass( USomething::StaticClass(), NULL, TEXT("MyPackage.Something"), NULL, LOAD_None, NULL );
//create object
USomething* SomethingObj = ConstructObject( SomethingClass, NewPkg, FName( TEXT("SomethingNew") ) );
//applies value to SomeString
SomethinObj->SomeString = FString(TEXT("Save me"));
//creates save path (in ..texturesOurPackage.ext)
FString SavePath = FString(TEXT("..//Textures"))+PkgName+FString(TEXT(".ext"));
//save package
SavePackage(NewPkg,SomethinObj,RF_Standalone, *SavePath,GWarn);

After execution object named SomethingNew will be saved in folder textures in package OurPackage.ext. Now if you want to load the thing just use:

USomething* SomethingObj = LoadObject( NULL, TEXT("OurPackage.SomethingNew"), NULL, LOAD_NoWarn, NULL );

As you can see extension really doesn't matter in UEngine (TEXT("OurPackage.SomethingNew")) it only tells what content might be found in the file.