Send and receive OSC 1.0 messages in bevy with rosc.
There are two core components to use OSC in bevy: The OscMethod, a component that can receive OSC messages at one or more address, and the OscDispatcher, which takes received OSC messages and delivers them to the matching OSC methods.
Start by adding an OscMethod to your entity
```rust
struct ExampleEntity;
struct ExampleBundle { t: ExampleEntity, oscmethod: OscMethod, }
/// Spawn ExampleBundle fn spawnentity(mut commands: Commands) { commands.spawnbundle(ExampleBundle { t: ExampleEntity, oscmethod: OscMethod::new(vec!["/some/osc/address".into()]).expect("Method address is valid"), }); } ```
Next you need to set up the dispatcher, which distributes received messages
```rust
fn sendmessage(mut disp: ResMut
disp.dispatch(vec![OscPacket::Message(new_msg)], method_query);
} ```
Then add a system that reacts to new messages!
rust
fn print_received_osc_packets(mut query: Query<(&ExampleEntity, &mut OscMethod), Changed<OscMethod>>) {
for (_, mut osc_method) in query.iter_mut() {
if let Some(msg) = osc_method.get_message() {
println!("OSC message received: {:?}", msg)
}
}
}
See examples/basic.rs for a full example.
| bevy | bevy_rosc | |------|-----------| | 0.8 | 0.3 | | 0.7 | 0.1 |