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
|
void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const
|
||||||
{
|
{
|
||||||
TArray<USceneComponent*> ActorComponents;
|
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
||||||
Actor->GetComponents(ActorComponents);
|
|
||||||
for (USceneComponent* SceneComponent: ActorComponents)
|
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
||||||
{
|
{
|
||||||
UPrimitiveComponent* PrimitiveComponent{Cast<UPrimitiveComponent>(SceneComponent)};
|
return;
|
||||||
if (IsValid(PrimitiveComponent))
|
|
||||||
{
|
|
||||||
PrimitiveComponent->SetEnableGravity(false);
|
|
||||||
PrimitiveComponent->SetSimulatePhysics(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActorRootComponent->SetEnableGravity(false);
|
||||||
|
ActorRootComponent->SetSimulatePhysics(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const
|
void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const
|
||||||
@@ -1422,17 +1420,15 @@ void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TArray<USceneComponent*> ActorComponents;
|
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
||||||
Actor->GetComponents(ActorComponents);
|
|
||||||
for (USceneComponent* SceneComponent: ActorComponents)
|
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
||||||
{
|
{
|
||||||
UPrimitiveComponent* PrimitiveComponent{Cast<UPrimitiveComponent>(SceneComponent)};
|
return;
|
||||||
if (IsValid(PrimitiveComponent))
|
|
||||||
{
|
|
||||||
PrimitiveComponent->SetEnableGravity(true);
|
|
||||||
PrimitiveComponent->SetSimulatePhysics(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActorRootComponent->SetEnableGravity(true);
|
||||||
|
ActorRootComponent->SetSimulatePhysics(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASGPawn::FImpl::~FImpl() = default;
|
ASGPawn::FImpl::~FImpl() = default;
|
||||||
|
|||||||
Reference in New Issue
Block a user