UE4 提供了很多数据持久的工具,很多…1,2,3
网上使用UE4 c++ 操作DataTable的也很多,不接入别人的链接了。
使用C++ 操作DataTable修改数据也没啥大的问题
坑爹的地方:
修改完数据之后,重启编辑器之后,修改的数据恢复之前的默认值了
解决办法:
引入模块
EditorScriptingUtilities
引入头文件
#include "EditorAssetLibrary.h"
使用代码
const TSoftObjectPtr<UDataTable> SourceDataTable;
UEditorAssetLibrary::SaveAsset(SourceDataTable.ToString(),false);
源码参考
/**
* Save the packages the assets live in. All objects that live in the package will be saved.
* Will try to checkout the file first. The Asset will be loaded before being saved.
* @param AssetsToSave Asset Path of the asset that we want to save.
* @param bOnlyIfIsDirty Only checkout/save the asset if it's dirty.
* @return True if the operation succeeds.
*/
UFUNCTION(BlueprintCallable, Category = "Editor Scripting | Asset")
static bool SaveAsset(const FString& AssetToSave, bool bOnlyIfIsDirty = true);