2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【UE5】UBT/UAT にビルド引数を渡して独自のプリプロセッサを定義する

Last updated at Posted at 2025-12-07

まず Build.cs に以下の変更を行う。MyArgMY_ARG の部分は自分のものに置き換えてください。

1. コマンドライン引数を定義する

[CommandLine("-MyArg")]
public bool bMyArg = false;

2. コマンドライン引数を適用する

new CommandLineArguments(Environment.GetCommandLineArgs()).ApplyTo(this);

3. プリプロセッサの定義を追加する

PublicDefinitions.Add($"MY_ARG={Convert.ToInt32(bMyArg)}");

まとめると以下のようになる。

MyProject.Build.cs
using EpicGames.Core;
using System;
using UnrealBuildTool;

public class MyProject : ModuleRules
{
	[CommandLine("-MyArg")]
	public bool bMyArg = false;

	public MyProject(ReadOnlyTargetRules Target) : base(Target)
	{
		// ...

		new CommandLineArguments(Environment.GetCommandLineArgs()).ApplyTo(this);

		PublicDefinitions.Add($"MY_ARG={Convert.ToInt32(bMyArg)}");
	}
}

この状態で UBT の場合は -MyArg、UAT の場合は -UBTArgs=-MyArg という引数を渡してビルドすれば #define MY_ARG 1 となり、以下のようなプリプロセッサでスイッチするコードを書けるようになる。

#if MY_ARG
    UE_LOG(LogTemp, Log, TEXT("MY_ARG=1"));
#else
    UE_LOG(LogTemp, Log, TEXT("MY_ARG=0"));
#endif

参考:

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?