Drag Gesture
A simple example of using DragGesture to move entities.
In this example we create a drag gesture that can target entities to allow us to move them in our scene.
struct Example007: View {
var body: some View {
RealityView { content in
// Load the scene from the Reality Kit bundle
if let scene = try? await Entity(named: "GestureLabs", in: realityKitContentBundle) {
content.add(scene)
// Lower the entire scene to the bottom of the volume
scene.position.y = -0.4
}
}
.gesture(dragGesture)
}
var dragGesture: some Gesture {
DragGesture()
.targetedToAnyEntity()
.onChanged { value in
value.entity.position = value.convert(value.location3D, from: .local, to: value.entity.parent!)
}
}
}Video Example
This is the most basic example of moving an entity. You may notice the entity “snap” from its current position when starting this gesture. This is because the location3D value from the gesture isn’t based on the position of the entity, but the position of the gesture on the entity.
Learn how to fix that by adding the initial position to the movement.
Support our work so we can continue to bring you new examples and articles.
Download the Xcode project with this and many more examples from Step Into Vision.
Some examples are provided as standalone Xcode projects. You can find those here.

Follow Step Into Vision