Prefabs and Reuse
This guide explains how to stop duplicating object setup across scenes.
What A Prefab Is
A prefab is a reusable object template saved as .prefab.php in Assets/Prefabs.
Use prefabs when:
- the object appears in multiple scenes
- the object is spawned at runtime
- you want one place to tune default values
Create A Prefab
You can create prefabs in three common ways:
Assets -> Shift+A -> Prefabsendama generate:prefab enemy-bullet- export existing scene object with
Hierarchy -> Shift+E
Prefab edits are written immediately.
Example Prefab Metadata
<?php
return [
'name' => 'EnemyBullet',
'type' => 'GameObject',
'transform' => [
'position' => ['x' => 0, 'y' => 0],
],
'renderer' => [
'texture' => 'Textures/enemy-bullet.texture',
],
'components' => [
[
'type' => Sendama\MyGame\Scripts\EnemyBullet::class,
'data' => [
'speed' => 8.0,
],
],
],
];
Place A Prefab In A Scene
Typical flow:
- author prefab
- place an instance in scene or reference it from another component
- save scene with
Ctrl+S - run
sendama play
Runtime Reuse Pattern
Prefabs are ideal for:
- bullets
- enemies
- pickups
- breakable props
This lets scene data and runtime spawning share the same object shape.
Rename Safety
When renaming prefab files:
- file rename applies immediately
- scene references may update in memory
- save scene to persist updated paths