글을 쓰는 목적
아웃 라이너에서 액터를 선택하는 방법을 기억하기 위해 글을 쓴다.
작업 환경
UE4.26
코드에서 아웃라이너 선택하기
에디터를 활용하다 보니 아웃라이너 선택 기능이 필요했다. 위젯 리플렉터로 아웃라이너 코드를 살피다보면 SSceneOutiner 코드에서 아웃라이너의 기능을 처리 함을 알 수 있다. 아래 코드 처럼 아웃라이너에서 액터를 선택하는 코드가 나와있다.
if ( bChanged )
{
const FScopedTransaction Transaction( NSLOCTEXT("UnrealEd", "ClickingOnActors", "Clicking on Actors"), !bAnyInPIE );
GEditor->GetSelectedActors()->Modify();
// Clear the selection.
GEditor->SelectNone(false, true, true);
// We'll batch selection changes instead by using BeginBatchSelectOperation()
GEditor->GetSelectedActors()->BeginBatchSelectOperation();
const bool bShouldSelect = true;
const bool bNotifyAfterSelect = false;
const bool bSelectEvenIfHidden = true; // @todo outliner: Is this actually OK?
for (auto* Actor : SelectedActors)
{
UE_LOG(LogSceneOutliner, Verbose, TEXT("Clicking on Actor (world outliner): %s (%s)"), *Actor->GetClass()->GetName(), *Actor->GetActorLabel());
GEditor->SelectActor( Actor, bShouldSelect, bNotifyAfterSelect, bSelectEvenIfHidden );
}
// Commit selection changes
GEditor->GetSelectedActors()->EndBatchSelectOperation(/*bNotify*/false);
// Fire selection changed event
GEditor->NoteSelectionChange();
}
코드를 살펴보면
수정이 될 예정이라고 설정
GEditor->GetSelectedActors()->Modify();
아웃라이너에 선택된 액터 해제
GEditor->SelectNone(false, true, true);
USelection에서 선택 시작과 종료시 실행
GEditor->GetSelectedActors()->BeginBatchSelectOperation();
GEditor->GetSelectedActors()->EndBatchSelectOperation(/*bNotify*/false);
아웃라이너에 액터 선택
const bool bShouldSelect = true;
const bool bNotifyAfterSelect = false;
const bool bSelectEvenIfHidden = true; // @todo outliner: Is this actually OK?
for (auto* Actor : SelectedActors)
{
UE_LOG(LogSceneOutliner, Verbose, TEXT("Clicking on Actor (world outliner): %s (%s)"), *Actor->GetClass()->GetName(), *Actor->GetActorLabel());
GEditor->SelectActor( Actor, bShouldSelect, bNotifyAfterSelect, bSelectEvenIfHidden );
}
부로 나뉘어 있음을 알 수 있다. 에디터 코드를 활용하여 아웃라이너에 액터를 선택할 때 참고하기 좋은 코드 같다.
주의점
BeginBatchSelectOperation과 EndBatchSelectOperation을 사용하지 않아도 SelectActor로도 작동하는데 다수의 액터를 선택하면 에디터가 느려지는 현상이 있다. 주의해야 한다.
'UE4' 카테고리의 다른 글
UE4 코드에서 DataTable 사용 (0) | 2022.04.18 |
---|---|
UE4 코드에서 MessageDialog 사용 (0) | 2022.04.18 |
UE4 Customized Property Layout 갱신 (0) | 2022.04.08 |
UE4 Widget Animation C++ (0) | 2022.02.23 |
[UE4][BUG] Android에서 시작 맵이 변경되지 않는 현상 (0) | 2021.12.21 |