프로그래밍/언리얼엔진

언리얼엔진 4 C++강좌 006 [actor-06] 에디터에서 설정하면 실시간으로 액터에 반영되도록 하기

panpro 2023. 10. 29. 15:22

에디터에서 빛의 세기를 바꾸면 실시간으로 그 값이 클래스의 인스턴스에서 반영되도록 수정해 봅니다. 

 

위 그림과 같이 우리가 만든 클래스에 빛의 세기를 조절하는 변수를 둘 수 있고, 에디터에서 보여줄 수도 있는데, 

에디터에서 "빛의 세기" 값을 조절해도 에디트 중에는 그 값이 실시간으로 보여지질 않습니다. 

 

그러니까, "빛의 세기" 값을 바꾸면 에디트 타임에도 반영이 되었으면 하는 것이죠. 

이게 언리얼엔진과 c++에서 가능합니다. 

 

// LampActor.h

virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;

위와 같이 헤더 파일에 PostEditChangeProperty 함수를 선언하고, 

 

// LampActor.cpp

#if WITH_EDITOR
void ALampActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	m_pLight->SetIntensity(m_nLightIntensity);

	Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

cpp 파일에서 #if WITH_EDITOR 로 감싸서 위와 같이 에디터에서 값이 변경될 때 실행할 내용을 적어주면 됩니다.

 

전체 소스코드 github: https://github.com/easyprogstudy/ue4cppS01

 

GitHub - easyprogstudy/ue4cppS01: Unreal Engine 4 C++ study

Unreal Engine 4 C++ study. Contribute to easyprogstudy/ue4cppS01 development by creating an account on GitHub.

github.com