get root component instead of iterating over the components in order to disable/enable the actor physics
This commit is contained in:
@@ -1402,17 +1402,15 @@ void ASGPawn::FImpl::UnbindFingerTouchOverlapEvents()
|
||||
|
||||
void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const
|
||||
{
|
||||
TArray<USceneComponent*> ActorComponents;
|
||||
Actor->GetComponents(ActorComponents);
|
||||
for (USceneComponent* SceneComponent: ActorComponents)
|
||||
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
||||
|
||||
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
||||
{
|
||||
UPrimitiveComponent* PrimitiveComponent{Cast<UPrimitiveComponent>(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<USceneComponent*> ActorComponents;
|
||||
Actor->GetComponents(ActorComponents);
|
||||
for (USceneComponent* SceneComponent: ActorComponents)
|
||||
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
||||
|
||||
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
||||
{
|
||||
UPrimitiveComponent* PrimitiveComponent{Cast<UPrimitiveComponent>(SceneComponent)};
|
||||
if (IsValid(PrimitiveComponent))
|
||||
{
|
||||
PrimitiveComponent->SetEnableGravity(true);
|
||||
PrimitiveComponent->SetSimulatePhysics(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ActorRootComponent->SetEnableGravity(true);
|
||||
ActorRootComponent->SetSimulatePhysics(true);
|
||||
}
|
||||
|
||||
ASGPawn::FImpl::~FImpl() = default;
|
||||
|
||||
Reference in New Issue
Block a user