본문 바로가기

Unreal

[Unreal] C++ 언리얼 헤더파일 include 하기

언리얼의 모듈이 저장된 장소

C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime

위 사진과 아래 사진은 같은 경로 입니다.

 

언리얼의 기능을 사용하고자 할때 헤더파일을 include 해야 합니다.

위에 폴더명 중에 사용하고자 하는 것이 있으면 

프로젝트명.Build.cs 파일을 열고, PublicDependencyModuleNames에 추가(add) 해야 합니다.

 

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Sockets.h"
#include "SocketSubsystem.h"
#include "IPAddress.h"
#include "CoreGlobals.h"
#include "ASync/Async.h"

#include "Test_Network.generated.h"




UCLASS()
class CPPTEST_API ATest_Network : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ATest_Network();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	UFUNCTION(BlueprintCallable, Category = "Test_Network")
	FString GetIpAddress();
};

추가한 폴더명 안의 헤더파일을 include 하면 에러없이 잘 빌드 됩니다.

 

#include "Test_Network.h"

// Sets default values
ATest_Network::ATest_Network()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;

}

// Called when the game starts or when spawned
void ATest_Network::BeginPlay()
{
	Super::BeginPlay();
	
}


FString ATest_Network::GetIpAddress()
{
	FString IpAddr("NONE");
	bool canBind = false;
	TSharedRef<FInternetAddr> LocalIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);
	if (LocalIp->IsValid())
	{
		IpAddr = LocalIp->ToString(false);
	}
	return IpAddr;
}

저는 Socket을 참조하여 내 컴퓨터 IP를 가져오는 테스트를 해봤습니다.