728x90
728x90
// 자식 컴포넌트를 클래스별로 찾는 함수
UChildComponent* UYourParentComponent::FindChildComponent()
{
// 모든 부착된 컴포넌트를 반복합니다
for (UActorComponent* Component : GetAttachChildren())
{
// 컴포넌트가 원하는 클래스인지 확인합니다
if (UChildComponent* ChildComponent = Cast<UChildComponent>(Component))
{
return ChildComponent;
}
}
// 일치하는 컴포넌트를 찾지 못한 경우 nullptr을 반환합니다
return nullptr;
}
```
이 예제에서:
- `UYourParentComponent`는 부모 컴포넌트의 클래스입니다.
- `UChildComponent`는 찾고자 하는 자식 컴포넌트의 클래스입니다.
- `GetAttachChildren()` 함수는 부모 컴포넌트에 부착된 모든 컴포넌트의 배열을 반환합니다.
- `Cast<UChildComponent>(Component)` 함수는 컴포넌트가 원하는 클래스인지 확인합니다.
728x90
반응형
'프로그래밍' 카테고리의 다른 글
UPrimitiveComponent와 USceneComponent의 차이점 in 언리얼5 (1) | 2024.11.12 |
---|---|
구조체 타입 로그 출력 팁! in 언리얼 (0) | 2024.11.10 |
액터 내 컴포넌트간 Collision 무시 방법 in 언리얼 (0) | 2024.11.07 |
언리얼5에서 파라미터 전달 타이머 만들기 (1) | 2024.11.04 |
UHierarchicalInstancedStaticMeshComponent 에서 인스턴스 제거 시 인덱스 변화 (4) | 2024.10.18 |