bool UGripMotionControllerComponent::GripActor( AActor* ActorToGrip, const FTransform &WorldOffset, bool bWorldOffsetIsRelative, FName OptionalSnapToSocketName, TEnumAsByte<EGripCollisionType> GripCollisionType, bool bAllowSetMobility, float GripStiffness, float GripDamping, bool bTurnOffLateUpdateWhenColliding ) { if (!bIsServer || !ActorToGrip) { UE_LOG(LogTemp, Warning, TEXT("VRGripMotionController grab function was passed an invalid or already gripped actor")); return false; } UPrimitiveComponent *root = Cast<UPrimitiveComponent>(ActorToGrip->GetRootComponent()); if (!root) { UE_LOG(LogTemp, Warning, TEXT("VRGripMotionController tried to grip an actor without a UPrimitiveComponent Root")); return false; // Need a primitive root } // Has to be movable to work if (root->Mobility != EComponentMobility::Movable) { if (bAllowSetMobility) root->SetMobility(EComponentMobility::Movable); else { UE_LOG(LogTemp, Warning, TEXT("VRGripMotionController tried to grip an actor set to static mobility and bAllowSetMobility is false")); return false; // It is not movable, can't grip it } } root->IgnoreActorWhenMoving(this->GetOwner(), true); // So that events caused by sweep and the like will trigger correctly ActorToGrip->AddTickPrerequisiteComponent(this); FBPActorGripInformation newActorGrip; newActorGrip.GripCollisionType = GripCollisionType; newActorGrip.Actor = ActorToGrip; newActorGrip.bOriginalReplicatesMovement = ActorToGrip->bReplicateMovement; newActorGrip.Stiffness = GripStiffness; newActorGrip.Damping = GripDamping; newActorGrip.bTurnOffLateUpdateWhenColliding = bTurnOffLateUpdateWhenColliding; if (OptionalSnapToSocketName.IsValid() && root->DoesSocketExist(OptionalSnapToSocketName)) { // I inverse it so that laying out the sockets makes sense FTransform sockTrans = root->GetSocketTransform(OptionalSnapToSocketName, ERelativeTransformSpace::RTS_Component); newActorGrip.RelativeTransform = sockTrans.Inverse(); newActorGrip.RelativeTransform.SetScale3D(ActorToGrip->GetActorScale3D()); } else if (bWorldOffsetIsRelative) newActorGrip.RelativeTransform = WorldOffset; else newActorGrip.RelativeTransform = WorldOffset.GetRelativeTransform(this->GetComponentTransform()); NotifyGrip(newActorGrip); GrippedActors.Add(newActorGrip); return true; }