Prefabs store reusable entity hierarchies as .fprefab JSON files.
Ctrl+Shift+M), or use PrefabSerializer.CreateFromEntity().fprefab from the asset browser into the viewport or hierarchy.fprefab propagate to all instances (overridden properties are preserved)| Operation | Shortcut | Description |
|---|---|---|
| Apply Prefab | Ctrl+Alt+P | Push instance overrides back to the source .fprefab |
| Revert Prefab | Ctrl+Alt+R | Discard instance overrides and match the source |
| Make Unique | Ctrl+Shift+U | Save a new .fprefab from this instance |
| Unpack | Ctrl+Alt+K | Break the prefab link, turning the instance into regular entities |
Spawn prefabs from scripts using Scene.Instantiate():
using FrinkyEngine.Core.ECS;
using FrinkyEngine.Core.Assets;
public class SpawnerComponent : Component
{
[AssetFilter(AssetType.Prefab)]
public AssetReference ProjectilePrefab { get; set; }
public override void Update(float dt)
{
if (Input.IsMouseButtonPressed(0))
{
// Spawn at a position and rotation
var entity = Entity.Scene.Instantiate(
ProjectilePrefab,
Transform.WorldPosition,
Transform.WorldRotation);
// Or spawn with just a path
// var entity = Entity.Scene.Instantiate("Prefabs/Bullet.fprefab");
// Optionally parent to another transform
// var entity = Entity.Scene.Instantiate(ProjectilePrefab, parent: someTransform);
}
}
}
All overloads accept an optional parent parameter. Entity references within the prefab are automatically remapped to the new instance.
Prefabs use stable IDs to track entities across edits and support nested hierarchies. When a prefab is instantiated, entity IDs are remapped so each instance gets unique IDs while maintaining internal cross-references.
EntityReference is a struct for linking one entity to another. It stores the target entity’s GUID and resolves at runtime.
using FrinkyEngine.Core.ECS;
public class MyComponent : Component
{
public EntityReference Target { get; set; }
public override void Update(float dt)
{
var entity = Target.Resolve(Scene);
if (entity != null)
{
// Use the referenced entity
var targetPos = entity.Transform.WorldPosition;
}
}
}
Scene.FindEntityById()Entity references are automatically remapped in these scenarios:
References to entities outside the duplicated/instantiated group remain unchanged.
Drag an entity from the hierarchy panel onto an EntityReference field in the inspector to assign it. The inspector shows the referenced entity’s name or “None” if unassigned.