From ff1021a977a3cf0dff1c8668acea7d936003cf78 Mon Sep 17 00:00:00 2001 From: Elliot Drees Date: Mon, 21 Jul 2025 17:59:27 -0400 Subject: [PATCH] docs: added entity spawn example --- docs/src/Examples/EntitySpawning.md | 28 ++++++++++++++++++++++++++++ docs/src/SUMMARY.md | 1 + 2 files changed, 29 insertions(+) create mode 100644 docs/src/Examples/EntitySpawning.md diff --git a/docs/src/Examples/EntitySpawning.md b/docs/src/Examples/EntitySpawning.md new file mode 100644 index 0000000000..ab1da916f4 --- /dev/null +++ b/docs/src/Examples/EntitySpawning.md @@ -0,0 +1,28 @@ +## Entity spawning + +Assuming you created a component and registered it using the following rust snippets. + +```rust,ignore +#[derive(Component, Reflect, Default)] +#[reflect(Component)] +pub struct MyType { + value: f32, +} +``` + +```rust,ignore +app.register_type::(); +``` + +In lua you can construct a MyType instance and attach it to an entity. + +```lua +local MyType = types.MyType + +function on_script_loaded() + local instance = construct(MyType, { value = 50.0 }) + local entity = world.spawn() + world.insert_component(entity, MyType, instance) + print("Entity with component value: " .. world.get_component(entity, MyType).value) +end +``` diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index cb80e83102..c3a7e80178 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -12,6 +12,7 @@ - [Script ID Mapping](./Summary/script-id-mapping.md) - [Script Systems](./ScriptSystems/introduction.md) - [Examples](./Examples/introduction.md) + - [Entity spawning](./Examples/EntitySpawning.md) # Scripting Reference