콘솔이 열리면 게임 설정 변경, 액터 스폰 또는 사용자 지정 스크립트 실행과 같은 다양한 작업을 수행할 수 있는 명령을 입력할 수 있다. 전반적으로 콘솔은 언리얼 엔진으로 작업하는 개발자에게 필수적인 도구로, 전체 프로젝트를 다시 컴파일하고 다시 시작하지 않고도 게임을 빠르게 테스트하고 디버그할 수 있는 방법을 제공한다.

 

목차

     

     


     

     

     

     
    Plugins
      Example
        Example.Build.cs
    ExampleConsoleCommand.h .cpp 
    ExampleDebuggerCategory.h .cpp
    ExampleModule.h .cpp
     

     

     

     

     

    Console Command

     

     


     

     

    FModuleManager::LoadModuleChecked

     

    FModuleManager::LoadModuleChecked<부를 자료형>("__PropertyEditor___") 

     

    https://docs.unrealengine.com/4.26/en-US/API/Runtime/Core/Modules/FModuleManager/LoadModuleChecked/1/

     

    FModuleManager::LoadModuleChecked

    Loads a module by name, checking to ensure it exists.

    docs.unrealengine.com

     

     


     

     

    언리얼 내장 명령어 모음

     

     

    https://digilander.libero.it/ZioYuri78/

     

    UE4 Console Variables and Commands

     

    digilander.libero.it


     

     

     

     

     

     

     

    명령어 실행하기 (Console Command)

     

     


     

     

    ExampleConsoleCommand

     

    ExampleConsoleCommand.h

    더보기
    #pragma once
    #include "CoreMinimal.h"
    
    class EXAMPLE_API FExampleConsoleCommand
    {
    public:
    	FExampleConsoleCommand();
    	~FExampleConsoleCommand();
    
    private:
    	struct IConsoleCommand* Command;
    	struct IConsoleCommand* Command2;
    
    private:
    	void ExecuteCommand();
    };

    구조체 생성

    • struct IConsoleCommand* Command;     
      • ViewMessageDialog 명령어
    • struct IConsoleCommand* Command2;   
      • ViewMessageArgs 명령어

     

    함수 생성

    • void ExecuteCommand();

     

     

    ExampleConsoleCommand.cpp

    더보기
    #include "ExampleConsoleCommand.h"
    #include "HAL/IConsoleManager.h"
    #include "Misc/MessageDialog.h" //메시지 창이 뜨는데 필요한 헤더
    
    FExampleConsoleCommand::FExampleConsoleCommand()
    {
    	FConsoleCommandDelegate command = FConsoleCommandDelegate::CreateRaw(this, &FExampleConsoleCommand::ExecuteCommand);
    
    	Command = IConsoleManager::Get().RegisterConsoleCommand(L"ViewMessageDialog", L"Move actor to position(FVector)", command); //싱글톤
    
    
    	FConsoleCommandWithArgsDelegate command2;
    	command2.BindLambda([&](const TArray<FString>& InArgs)
    	{
    		FString content;
    		for (FString str : InArgs)
    			content += ", " + str;
    
    		FMessageDialog::Debugf(FText::FromString(content));//content 출력
    	});
    
    	Command2 = IConsoleManager::Get().RegisterConsoleCommand(L"ViewMessageArgs", L"Move actor to position(FVector)", command2);
    }
    
    FExampleConsoleCommand::~FExampleConsoleCommand()
    {
    	if (!!Command)
    		IConsoleManager::Get().UnregisterConsoleObject(Command); //Command 제거
    
    	if (!!Command2)
    		IConsoleManager::Get().UnregisterConsoleObject(Command2); //Command2 제거
    }
    
    void FExampleConsoleCommand::ExecuteCommand()
    {
    	FText title = FText::FromString("Warning");
    	FText context = FText::FromString("Don't move, Need position input");
    
    	FMessageDialog::Debugf(context, &title);
    }

     

     


     

     

    명령어 실행하기 -  ViewMessageDialog

     

     

     


     

     

    명령어 실행하기 -  ViewMessageArgs

     

     


     

     

     

     

     

     

     

     

     

    플레이어 이동시키기

     


     

     

    ExampleConsoleCommand -  Command3 명령 추가

     

    ExampleConsoleCommand.h

    더보기
    #pragma once
    #include "CoreMinimal.h"
    
    class EXAMPLE_API FExampleConsoleCommand
    {
    public:
    	FExampleConsoleCommand();
    	~FExampleConsoleCommand();
    
    private:
    	struct IConsoleCommand* Command;
    	struct IConsoleCommand* Command2;
    	struct IConsoleCommand* Command3; //플레이어 이동 명령
    
    private:
    	void ExecuteCommand();
    	void ExecuteCommand3(const TArray<FString>& InArgs, UWorld* InWorld);
    };

    구조체 생성

    • struct IConsoleCommand* Command3;     
      • MoveToPlayer 명령어

     

     

    ExampleConsoleCommand.cpp

    더보기
    #include "ExampleConsoleCommand.h"
    #include "HAL/IConsoleManager.h"
    #include "Misc/MessageDialog.h" //메시지 창이 뜨는데 필요한 헤더
    #include "GameFramework/Character.h"
    
    FExampleConsoleCommand::FExampleConsoleCommand()
    {
    	FConsoleCommandDelegate command = FConsoleCommandDelegate::CreateRaw(this, &FExampleConsoleCommand::ExecuteCommand);
    
    	Command = IConsoleManager::Get().RegisterConsoleCommand(L"ViewMessageDialog", L"Move actor to position(FVector)", command); //싱글톤
    
    
    	FConsoleCommandWithArgsDelegate command2; 
    	command2.BindLambda([&](const TArray<FString>& InArgs)
    	{
    		FString content;
    		for (FString str : InArgs)
    			content += ", " + str;
    
    		FMessageDialog::Debugf(FText::FromString(content));//content 출력
    	});
    
    	Command2 = IConsoleManager::Get().RegisterConsoleCommand(L"ViewMessageArgs", L"Move actor to position(FVector)", command2);
    
    
    	FConsoleCommandWithWorldAndArgsDelegate command3; //게임상의 World를 리턴
    	command3.BindRaw(this, &FExampleConsoleCommand::ExecuteCommand3);
    
    	Command3 = IConsoleManager::Get().RegisterConsoleCommand(L"MoveToPlayer", L"Move player to position(FVector)", command3);
    
    }
    
    FExampleConsoleCommand::~FExampleConsoleCommand()
    {
    	if (!!Command)
    		IConsoleManager::Get().UnregisterConsoleObject(Command); //Command 제거
    
    	if (!!Command2)
    		IConsoleManager::Get().UnregisterConsoleObject(Command2); //Command2 제거
    
    	if (!!Command3)
    		IConsoleManager::Get().UnregisterConsoleObject(Command3); //Command3 제거
    
    }
    
    void FExampleConsoleCommand::ExecuteCommand()
    {
    	FText title = FText::FromString("Warning");
    	FText context = FText::FromString("Don't move, Need position input");
    
    	FMessageDialog::Debugf(context, &title);
    
    }
    
    void FExampleConsoleCommand::ExecuteCommand3(const TArray<FString>& InArgs, UWorld* InWorld)
    {
    	//100,200,300
    	if(InArgs.Num() != 1)
    	{
    		GLog->Log("FVector format required input");
    
    		return;
    	}
    
    	TArray<FString> strs;
    	InArgs[0].ParseIntoArray(strs, L","); //strs 문자열을 배열로 분할해서 사용.
    
    	FVector position;
    	position.X = FCString::Atof(*strs[0]); //FCString은 char를 다룬다.
    	position.Y = FCString::Atof(*strs[1]);
    	position.Z = FCString::Atof(*strs[2]);
    
    	if(FApp::IsGame()) //GameMode인 상황
    	{
    		APlayerController* controller = InWorld->GetFirstPlayerController<APlayerController>();
    		ACharacter* character = controller->GetPawn<ACharacter>(); //controller에 빙의된 character(=player)를 찾는다. 
    
    		character->SetActorLocation(position); //character(=player)를 position으로 이동시킨다.
    
    		return;
    	}
    
    	for(AActor* actor : InWorld->GetCurrentLevel()->Actors)//GameMode가 아닌 상황 //InWorld->GetCurrentLevel()는 에디터 상에 열려있는 Level를 의미한다.
    	{
    		if (!!actor && actor->GetName().Contains("PlayerStart"))//actor의 이름이 "PlayerStart"를 포함하고 있다면
    			actor->SetActorLocation(position); //actor를 position 위치로 이동시킨다.
    	}
    }

     

     

     

     

     

    ※ 참고: FConsoleCommandWithWorldAndArgsDelegate

    FConsoleCommandWithWorldAndArgsDelegate는 게임상의 World를 리턴한다.

     

     

     

    ※ 참고: ParseIntoArray

    ParseIntoArrayOutArray로 들어온 문자열을 pchDelim 시점에서 배열로 분할한다.

    위의 코드의 경우 strs로 들어온 문자열을 L" , "에서 분할한다. 

     

     


     

     

     

    명령어 실행하기 - MoveToPlayer 숫자,숫자,숫자

     

     


     

     

     

     

    실행화면

     

     

     


     

    '⭐ Unreal Engine > UE Plugin - Basic' 카테고리의 다른 글

    [UE] Plugin (Save StaticMesh & RenderData, LOD)  (0) 2023.04.12
    [UE] Plugin (StaticMesh Detail)  (0) 2023.04.07
    [UE] StaticMesh  (0) 2023.04.06
    [UE] Console, DrawDebugLine  (0) 2023.04.04
    [UE] Plugin, Slate UI  (0) 2023.04.03