11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[UE4] コマンドレットを使って、コマンドラインに任意の処理を実装する

Posted at

コマンドレットとは

コマンドラインから実行可能な、UE4エンジンに組み込まれたコマンドラインアプレットです。
開発中の様々な処理を、UE4エディタのパワフルな機能を用いて自動化することが可能になります。
デフォルトで多くのコマンドレットが提供されています。
UCommandlet | Unreal Engine http://api.unrealengine.com/INT/API/Runtime/Engine/Commandlets/UCommandlet/index.html
Commandlets | Unreal Engine http://api.unrealengine.com/INT/API/Editor/UnrealEd/Commandlets/index.html

コマンドレットを実装

コマンドレット名は TestCmdFunction とします。
UCommandlet を継承して、 int32 Main(const FString&) をオーバーライドします。

TestCmdFunctionCommandlet.h
#pragma once
#include "CoreMinimal.h"
#include "Commandlets/Commandlet.h"
#include "TestCmdFunctionCommandlet.generated.h"

UCLASS()
class UTestCmdFunctionCommandlet : public UCommandlet
{
	GENERATED_UCLASS_BODY()
	
public:
	virtual int32 Main(const FString& CmdLineParams) override;
};

Constructorint32 Main(const FString&) を実装します。

TestCmdFunctionCommandlet.cpp
#include "TestCmdFunctionCommandlet.h"

DEFINE_LOG_CATEGORY_STATIC(LogTestCmdFunctionCommandlet, Log, All);

UTestCmdFunctionCommandlet::UTestCmdFunctionCommandlet(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	LogToConsole = false;
}

int32 UTestCmdFunctionCommandlet::Main(const FString& CmdLineParams)
{
	FString Value;
	if (FParse::Value(*CmdLineParams, TEXT("param0="), Value))
	{
		UE_LOG(LogTestCmdFunctionCommandlet, Display, TEXT("param0=%s"), *Value);
		return 0;
	}
	return 1;
}

コマンドレットを呼び出す

/PATH/TO/ENGINEROOT/Engine/Binaries/Win64/UE4Editor-Cmd.exe /PATH/TO/PROJECTROOT/MyGame.uproject -run=TestCmdFunction -param0=hogehoge -stdout -UTF8Output
11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?