Skip to content

docs: added entity spawn example #440

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/src/Examples/EntitySpawning.md
Original file line number Diff line number Diff line change
@@ -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::<MyType>();
```

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
```
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down