티스토리 뷰

개발/UE4

[UE4] 런타임 컴포넌트 생성

LazySonic 2021. 9. 27. 16:10

컴포넌트를 만들어 액터에 붙이는 시점은 아래 세 부분 정도로 나눠 볼 수 있다.

1. class construction 과정
2. blueprint construction 과정
3. beginplay 혹은 그 이후 과정

이때 대부분은 엔진 내 블루프린트 뷰에서 컴포넌트를 확인하기 위해 actor의 class construction 과정에서  
'CreateDefaultSubobject' 함수를 통해 생성하고 초기화한다.

이런 경우, ActorConstruction (BeginPlay나 OnConstruction 이전)에서 Actor 내 Component를 등록하고 초기화한다.

하지만 ActorConstruction 이후 즉 BeginPlay나 OnConstruction에서 컴포넌트를 생성하는 경우 컴포넌트 등록과 초기화를 수동으로 해줘야 한다.

따라서, 컴포넌트를 동적으로 만들어야하 하는 경우, Runtime Created Components 와 같은 명의 동적 컴포넌트 관리 자료구조를 두고 Manual 한 초기화를 해주는 것이 좋다.

간략하게 보면 아래와 같을 것 이다.

void RegisterRuntimeCreatedComponents()
{
	for (auto& RuntimeComp : UnregisteredRuntimeComponents)
	{
		if (RuntimeComp.Get())
		{
			RuntimeComp->RegisterComponent();
			if (RuntimeComp->HasBeenInitialized() == false)
			{
				RuntimeComp->InitializeComponent();
			}
		}
	}
}
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함