ECS and array of gestures

Hi,

I am creating an ECS. With this ECS I will need to register several DragGesture.

Question: Is it possible to define DragGestures in ECS? If yes, how do we do that? If not, what is the best way to do that?

Question: Is there a "gesture" method that takes an array of gestures as a parameter?

I am interested in any information that can help me, if possible with an example of code.

Regards

Tof

You can use gestures in your systems. Apple has a couple of example projects that show some methods for creating components and systems that use SwiftUI gestures

Transforming RealityKit entities using gestures https://developer.apple.com/documentation/realitykit/transforming-realitykit-entities-with-gestures

While not the focus of the example, this particle example also has an interesting system. Simulating particles in your visionOS app https://developer.apple.com/documentation/realitykit/simulating-particles-in-your-visionos-app

Both of these have been helpful in learning how to use gestures from within a system.

Hello @ZeTof

DragGesture is a part of SwiftUI while RealityKit contains APIs for interacting with and composing entities for your ECS. SwiftUI and RealityKit are separate but compatible frameworks. Of course, when you use both SwiftUI and RealityKit in the same app you'll need some way to communicate between the SwiftUI and RealityKit (ECS) layers, and @radicalappdev is right to suggest taking a look at Transforming RealityKit entities using gestures since this project is an example of exactly how to do that.



To answer your first question, the best (and only) way to setup a DragGesture is to apply it to your SwiftUI View with a gesture modifier.



To answer your second question, see the documentation for Composing SwiftUI gestures. You can't pass an array of gestures to a single gestures modifier, but you can use SequenceGesture to combine multiple gestures to be processed in sequence or SimultaneousGesture to combine gestures that should be processed at the same time.

A gesture and its callbacks are not part of the ECS. However, in the onChanged and onEnded closures for gestures you can modify your entities and perform queries on the scene, which should give you access to any ECS data you might want to modify.



Thanks for your question! Let me know if there's any thing else I can help you with.

ECS and array of gestures
 
 
Q