게임 개발/Unreal Engine

[Unreal Engine] 콘솔 커맨드 제작 방법 (Console Command)

지노윈 2023. 3. 7. 21:00
반응형

RegisterConsoleCommand 사용 방법

void UMyConsoleCommand::RegisterConsoleCommands()
{
    FConsoleCommandWithArgsDelegate SpawnCmdDelegate;
    SpawnCmdDelegate.BindUObject(this, &UMyConsoleCommand::EXEC_SpawnNpc);

    IConsoleManager::Get().RegisterConsoleCommand(
        TEXT("spawn.npc"),
        TEXT("spawn.npc [BP이름] [Count] [Distance]"), SpawnCmdDelegate);
}
    
void UMyConsoleCommand::EXEC_SpawnNpc(const TArray<FString>& Args)
{
	if (Args.Num() < 1)
		return;

	const FString& CharacterName = Args[0];
	const int Count = Args.Num() >= 2 ? FCString::Atoi(*Args[1]) : 1;
	const int Distance = Args.Num() >= 3 ? FCString::Atoi(*Args[2]) : 500;
    
    ...
 }

 

UFunction(Exec) 사용 방법

UFUNCTION(Exec)
void SpawnNpc(FString& CharacterName, int Count, int Distance);

 

TAutoConsoleVariable<Type> 사용 방법

// 정의
static TAutoConsoleVariable<float> AttackSpeed(
    TEXT("AttackSpeed"), // console command
    1,	// default
    TEXT("Changes attack speed to [value]") // help
);

// 사용
float AttackSpeed = AttackSpeed.GetValueOnGameThread();