https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Components/UActorComponent/OnRegister/
플레이어 캐릭터에 추가한 ActorComponent에서 플레이어 캐릭터에 접근할 때마다 Cast으로 형을 변환하는 것이 귀찮아질 때 다음과 같이 ActorComponent를 상속 받는 클래스를 생성하여 OnRegister함수에서 GetOwner함수 받은 Actor를 형변환하여 변수로 저장하는 방법을 사용한다.
ActorComponent의 OnRegister함수는 ActorComponent가 Actor에 등록될 때 호출되는 함수로, 초기화 단계에서 무언가를 수행하고 할 때 사용할 수 있습니다.
void UPRBaseActorComponent::OnRegister()
{
Super::OnRegister();
InitializePROwner();
}
void UPRBaseActorComponent::InitializePROwner()
{
APRBaseCharacter* NewPROwner = Cast<APRBaseCharacter>(GetOwner());
if(IsValid(NewPROwner) == true)
{
PROwner = NewPROwner;
}
}
'Unreal Engine > etc.' 카테고리의 다른 글
[Unreal Engine etc.] 캐릭터의 스켈레톤에 Root Bone 추가하기 (1) | 2024.01.23 |
---|---|
[Unreal Engine etc.] .pmx파일을 .fbx로 변환하여 Unreal Engine에 임포트 하기 (0) | 2024.01.23 |
[Unreal Engine etc.] C++에서 CineCameraComponent 사용 (0) | 2023.11.10 |
[Unreal Engine 4 etc.] GlobalTimeDilation과 Tick, Timer (0) | 2023.08.16 |
[Unreal Engine 4 etc.] AddMovementInput 관련 (0) | 2022.09.16 |