-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically Register Bevy Events #159
Comments
This can be an issue due to dependency on Dependency on Resource is due to the fact that we need a way to store the event so we can manage it |
I made some progress by wrapping the events into structs that implemented the needed traits. Other changes regarding registration were made, but here's an example for use std::any::TypeId;
use bevy::{
input::gamepad::{GamepadConnection, GamepadConnectionEvent, GamepadEvent},
prelude::*,
reflect::GetTypeRegistration,
};
use crate::prelude::EditorRegistryBevyExt;
pub(crate) trait BevyEvent:
Event + Default + Resource + Reflect + Send + Clone + 'static + GetTypeRegistration
{
type T: Event + Clone;
fn inner_event(&self) -> &Self::T;
fn inner_path() -> String {
std::any::type_name::<Self::T>().to_string()
}
fn inner_type_id() -> TypeId {
TypeId::of::<Self::T>()
}
}
#[derive(Event, Resource, Reflect, Clone)]
pub(crate) struct WrappedGamepadEvent(GamepadEvent);
impl Default for WrappedGamepadEvent {
fn default() -> Self {
Self(GamepadEvent::Connection(GamepadConnectionEvent {
gamepad: Gamepad::new(0),
connection: GamepadConnection::Disconnected,
}))
}
}
impl BevyEvent for WrappedGamepadEvent {
type T = GamepadEvent;
fn inner_event(&self) -> &Self::T {
&self.0
}
}
pub(crate) fn register_events(app: &mut App) -> &mut App {
app.editor_registry_bevy_event::<WrappedGamepadEvent>()
.register_type::<GamepadEvent>()
.register_type::<GamepadConnectionEvent>()
} |
I think you might need to wrap the subtypes as well or this type depends on something else that is not available (like |
This is the way I thought about doing it as well and how we did with XPBD |
You're probably right. I have this right now: pub(crate) fn register_events(app: &mut App) -> &mut App {
app.editor_registry_bevy_event::<WrappedGamepadEvent>()
.register_type::<GamepadEvent>()
.register_type::<GamepadConnection>()
.register_type::<GamepadConnectionEvent>()
.register_type::<GamepadButtonChangedEvent>()
.register_type::<GamepadAxisChangedEvent>()
.register_type::<GamepadInfo>()
} But still no luck. I'll come back to this later. |
Seems like all the subtypes need |
Agreed to the brittleness, but that is the way I also thought about it. Sadly, every new bevy update would mean A LOT OF CHANGES |
@ncomendant can you merge your current work into this branch? issue-159 |
Once issue #158 is resolved,
SpaceEditorPlugin
should register all of Bevy's events usingApp::editor_registry_event()
. This is similar to how it is done for components.The text was updated successfully, but these errors were encountered: