アウトライナに存在するアクターのインスタンスを何らかの方法で保存して再度利用できるようにする方法を探しています。
一応UObjectのコピーとペーストに関連しそうなクラスとしてUObject::ImportCustomProperties()とUExporter::ExportToOutputDevice等があります。考えていた方法では複数のアクター達からC++側でコピーしたテキストを保存するというものになります。
まだ試していないのですがUObject::ImportCustomProperties()のソースコードのコメントにCopy&Paste機能のオーバライドに関する記述があるので関係していそうです。
C++で実現する方法をご存じでしたら教えていただきたいです。
お世話になっております。
UExporter::ExportToFile を用いてペースト可能なアクター情報文字列をファイル出力することできます。
`/**
- Export this object to a file. Child classes do not override this, but they do provide an Export() function
- to do the resource-specific export work.
- @param Object the object to export
- [Content removed] attempts to create a valid exporter.
- @param Filename the name of the file to export this object to
- @param InSelectedOnly @todo
- [Content removed] even if they’re identical
- @param Prompt true if the user should be prompted to checkout/overwrite the output file if it already exists and is read-only
- [Content removed] 0 if a fatal error was encountered during export
/
ENGINE_API static int32 ExportToFile( UObject Object, UExporter* Exporter, const TCHAR* Filename, bool InSelectedOnly, bool NoReplaceIdentical=false, bool Prompt=false );`この場合第一パラメータ(Object)には Actor ではなく World を渡すことになります。
出力したいアクターを選択状態にしておき、第四パラメータ(IsSelectedOnly)を true とすることで出力対象アクターを制御します。
例えば以下のようにできます(エディタモジュール(UnrealEd)に依存します)。
`#include “Exporters/Exporter.h”
include “Editor.h”
include “Subsystems/EditorActorSubsystem.h”
void UMyBlueprintFunctionLibrary::ExportActorsToFile(const TArray<class AActor*>& Actors, const FString& FilePath)
{
if (Actors.IsEmpty())
{
return;
}
UEditorActorSubsystem* EditorActorSubsystem = GEditor->GetEditorSubsystem();
EditorActorSubsystem->SetSelectedLevelActors(Actors);
UWorld *World = Actors[0]->GetWorld();
UExporter::ExportToFile(World, nullptr, *FilePath, true);
}`よろしくお願いいたします。
お世話になっております。
承知しました。お示しいただいた関数でファイル書き出しができるのですね。
質問クローズしていただいて構いません。
ご確認ありがとうございます。
下記忘れましたが、ExportToFile 関数に渡す FilePath においては拡張子を .T3D とする必要があります点にご注意下さい。
本件はクローズいたします。
また何かありましたらお問い合わせ下さい。