diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index 6d98ef23..a9ef4404 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -1402,17 +1402,15 @@ void ASGPawn::FImpl::UnbindFingerTouchOverlapEvents() void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const { - TArray ActorComponents; - Actor->GetComponents(ActorComponents); - for (USceneComponent* SceneComponent: ActorComponents) + UPrimitiveComponent* ActorRootComponent{Cast(Actor->GetRootComponent())}; + + if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!"))) { - UPrimitiveComponent* PrimitiveComponent{Cast(SceneComponent)}; - if (IsValid(PrimitiveComponent)) - { - PrimitiveComponent->SetEnableGravity(false); - PrimitiveComponent->SetSimulatePhysics(false); - } + return; } + + ActorRootComponent->SetEnableGravity(false); + ActorRootComponent->SetSimulatePhysics(false); } void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const @@ -1422,17 +1420,15 @@ void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const return; } - TArray ActorComponents; - Actor->GetComponents(ActorComponents); - for (USceneComponent* SceneComponent: ActorComponents) + UPrimitiveComponent* ActorRootComponent{Cast(Actor->GetRootComponent())}; + + if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!"))) { - UPrimitiveComponent* PrimitiveComponent{Cast(SceneComponent)}; - if (IsValid(PrimitiveComponent)) - { - PrimitiveComponent->SetEnableGravity(true); - PrimitiveComponent->SetSimulatePhysics(true); - } + return; } + + ActorRootComponent->SetEnableGravity(true); + ActorRootComponent->SetSimulatePhysics(true); } ASGPawn::FImpl::~FImpl() = default;