🎮

「UnrealEngine」Actorの動作を完全に無効化する方法

に公開

UE:5.5.4

発生した問題

UnityのGameObject.SetActive(false)のように、
オブジェクトそのものを無効化する機能を作成したい。

方法


Actor->SetActorHiddenInGame(true);
Actor->SetActorTickEnabled(false);
Actor->SetActorEnableCollision(false);

// 全てのコンポーネントのTickを停止
TArray<UActorComponent*> Components;
Actor->GetComponents(Components);
for (auto* Component : Components)
{
    Component->SetComponentTickEnabled(false);
    Component->bAutoActivate = false; //これが見落とされがち
    Component->SetActiveFlag(false);
}

Component->bAutoActivateをfalseにしないと完全停止にならなかった。
たどり着くのにそこそこ時間を費やしたので記事にしておく。

参考文献:
https://forums.unrealengine.com/t/cannot-disable-actorcomponent-ticking/393773/5

Discussion