Comments (2)
I see, I think you're likely missing #[reflect(Reflect, Default)]
, here is an example which seems to work:
use bevy::app::AppExit;
use bevy::prelude::*;
use bevy_mod_scripting::prelude::*;
use bevy_script_api::lua::{bevy::LuaBevyAPIProvider, RegisterForeignLuaType};
#[derive(Component, Default, Reflect)]
#[reflect(Component, Default)]
pub struct DefComponent;
fn main() -> std::io::Result<()> {
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.add_plugins(ScriptingPlugin)
.register_type::<DefComponent>()
// note the implementation for Option is there, but we must register `LuaProxyable` for it
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
.add_systems(Startup, |world: &mut World| {
let entity = world.spawn(()).id();
// run script
world.resource_scope(|world, mut host: Mut<LuaScriptHost<()>>| {
host.run_one_shot(
r#"
function once()
local my_component_type = world:get_type_by_name("DefComponent")
print("before: ", world:get_component(entity, my_component_type))
world:add_default_component(entity, my_component_type)
print("after: ", world:get_component(entity, my_component_type))
end
"#
.as_bytes(),
"script.lua",
entity,
world,
LuaEvent {
hook_name: "once".to_owned(),
args: (),
recipients: Recipients::All,
},
)
.expect("Something went wrong in the script!");
});
world.send_event(AppExit)
});
app.run();
Ok(())
}
with the output being:
before: nil
after: bevy_api_lua::DefComponent
from bevy_mod_scripting.
You were right on the money, adding the reflect line to my struct got everything working right.
from bevy_mod_scripting.
Related Issues (20)
- Bevy 0.12 HOT 2
- Can't compile with mlua anymore HOT 4
- Rune - Proxy macros HOT 2
- Luajit feature does not build. Other build issues as well. HOT 2
- lua globals are not registered until callback function. HOT 16
- tealr macro does not play nice with re-exported bevy_mod_scripting_lua crate
- Request: More exaustive tealr docgen example would be nice HOT 1
- REQUEST: Add instructions to readme on how to use bevy api gen HOT 2
- Registering a Bundle for Lua HOT 5
- Improved trait system
- Unified documentation Frontend + Backend
- Support for pre-processing HOT 1
- Feature for shared context
- Panic when mutating world from proxied raw method HOT 4
- Support for bevy 0.13.2 HOT 2
- Consider adding a WebAssembly interpreter as a host HOT 1
- Indexing the `Children` component always yields `nil` HOT 3
- Expose the proxy types for Bevy builtins HOT 10
- Support for bevy 0.14 HOT 3
- luau?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy_mod_scripting.