(资料图片仅供参考)
有时间项目需求要将一系列的游戏数据保存为蓝图资产,然后在其他地方使用。
UMyDataSave 为要继承自UObject的蓝图
UCLASS()class XXXXX_API UMyDataSave : public UObject{ GENERATED_BODY()public: UPROPERTY(EditAnywhere,BlueprintReadWrite) int32 IntData;
}
函数声明:保存蓝图资产到AssetPath,并返回该资产的软对象引用
static bool SaveMyData(const FString& AssetPath, const FString& ObjectName, const TSoftObjectPtr<UMyDataSave >& MyDataSaveObj,int32 nData);
bool UBPEditorTool::SaveMyData(const FString& AssetPath, const FString& ObjectName,TSoftObjectPtr<UCubeWaveData>& CubeWaveDataObj){ FString PackageFileName = FPackageName::LongPackageNameToFilename(AssetPath, FPackageName::GetAssetPackageExtension()); UPackage* Package = CreatePackage(*AssetPath); Package->FullyLoad(); // 创建对象时,指定他对应的Package就是刚才创建的空资源Package UMyDataSave * pMyData = NewObject<UMyDataSave >(Package, FName(*ObjectName), EObjectFlags::RF_Public | EObjectFlags::RF_Standalone); //此处可以填充 pMyData 的数据
pMyData ->IntData = nData;
UE_LOG(LogTemp, Display, TEXT("SaveMyData:Path:%s,FileName:%s"),*AssetPath,*PackageFileName); // 保存这个对象到一个指定路径的uasset文件 bool bSaved = UPackage::SavePackage(Package, pWaveData, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError); FSoftObjectPath SolftObjPath = FSoftObjectPath(pWaveData); CubeWaveDataObj = TSoftObjectPtr<UCubeWaveData>(SolftObjPath); return bSaved;}
X 关闭
Copyright © 2015-2022 青年五金网版权所有 备案号:皖ICP备2022009963号-20 联系邮箱:39 60 291 42@qq.com