初めて質問します。
ゲーム中に写真を取って保存したいです。
参考になるサイトを探して、ココ(How can I save a RenderTarget or a Texture to a file? - Asset Creation - Epic Developer Community Forums)にのっているものが使えそうだと感じました。これをBPのノードとして作り、使いたいです。BPのノードをC++で作る方法はここ(UE4 C++コードをブループリントで使えるようにする(関数ライブラリー編) - Let's Enjoy Unreal Engine)を参考にしてやればできると思い、やってみたのですが、エラーが出ました。
UE4とC++は始めたばかりで、具体的にどうやったらエラーが解決できるのかわかりません。
エラーは、.hでUCLASS()が「この宣言にはストレージクラスまたは型指定子がありません」となってしまうのと、.cppで、InRenderTargetが「不完全クラス型へのポインターは使用できません」となってしまっているもの、それと、下にコピペしたものがどうしたらいいのかわからないです。
おしえていただけたら嬉しいです。
// .h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
/**
*
*/
UCLASS()
class GAMESYSTEM_1_API USaveTarget : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "MyBPLibrary")
static void SaveRenderTargetToDisk(UTextureRenderTarget2D* InRenderTarget, FString Filename);
};
//.cpp
#include "SaveTarget.h"
#include "HighResScreenshot.h"
#include "TextureResource.h"
#include "TextureRender"
void SaveRenderTargetToDisk(UTextureRenderTarget2D* InRenderTarget, FString Filename)
{
FTextureRenderTargetResource* RTResource = InRenderTarget -> GameThread_GetRenderTargetResource();
FReadSurfaceDataFlags ReadPixelFlags(RCM_UNorm);
ReadPixelFlags.SetLinearToGamma(true);
TArray<FColor> OutBMP;
RTResource->ReadPixels(OutBMP, ReadPixelFlags);
for (FColor& color : OutBMP)
{
color.A = 255;
}
FIntRect SourceRect;
FIntPoint DestSize(InRenderTarget->GetSurfaceWidth(), InRenderTarget->GetSurfaceHeight());
FString ResultPath;
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.SaveImage(Filename, OutBMP, DestSize, &ResultPath);
}
//error
エラー No #include found for the .generated.h file - the .generated.h file should always be the last #include in a header GameSystem_1 D:\UE4_projects\GameSystem_1\Intermediate\ProjectFiles\LogCompile 1
エラー Expected an include at the top of the header: ‘#include “SaveTarget.generated.h”’ GameSystem_1 D:\UE4_projects\GameSystem_1\Source\GameSystem_1\SaveTarget.h 24
エラー UnrealHeaderTool failed for target ‘GameSystem_1Editor’ (platform: Win64, module info: D:\UE4_projects\GameSystem_1\Intermediate\Build\Win64\GameSystem_1Editor\Development\GameSystem_1Editor.uhtmanifest, exit code: OtherCompilationError (5)). GameSystem_1 D:\UE4_projects\GameSystem_1\Intermediate\ProjectFiles\EXEC 1
エラー MSB3075 コマンド ““C:\Program Files\Epic Games\UE_4.17\Engine\Build\BatchFiles\Build.bat” GameSystem_1Editor Win64 Development “D:\UE4_projects\GameSystem_1\GameSystem_1.uproject” -waitmutex” はコード 5 で終了しました。このコマンドを実行するための十分な権限があるか確認してください。 GameSystem_1 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets 41