Ctrl+K

Prefab

Declaration

public class Strawberry.Core.Prefab

A pre-built template for spawning entities. Construct one from an existing entity (via Prefab) or fluently via PrefabBuilder, then call Instantiate to spawn copies. Asset references (Sprite, Texture, etc.) are serialized by name at snapshot time and resolved by name at instantiation time.

Inherits: Strawberry.DisposableReferenceObject

Constructors

Prefab

Creates a prefab by snapshotting the components currently on templateEntity. Asset references are resolved to names via snapshotAssets.

void Prefab(Entity templateEntity, AssetManager snapshotAssets = null)

Parameters:

Name Type Description
templateEntity Strawberry.Core.Entity The entity to snapshot.
snapshotAssets Strawberry.Core.AssetManager = null AssetManager used to resolve asset → name. Usually the global manager. Can be null if the prefab contains no asset references.

Methods

Instantiate

Instantiates a new entity with this prefab's components, resolving asset references via instantiateAssets.

Entity Instantiate(Scene scene, AssetManager instantiateAssets = null, Vector2? position = null)

Parameters:

Name Type Description
scene Strawberry.Core.Scene The scene the new entity will belong to.
instantiateAssets Strawberry.Core.AssetManager = null AssetManager used to resolve name → asset at instantiation time. Usually the scene's local manager (which falls back to the global one). Can be null if the prefab contains no asset references.
position Strawberry.Math.Vector2? = null Optional world position. If null, the template's position is used. Ignored if the prefab has no TransformComponent.

Returns: The newly created entity, already added to the scene.

InstantiateDetached

Instantiates without adding to a scene. Useful for pooling.

Entity InstantiateDetached(Scene scene, AssetManager instantiateAssets = null)

Parameters:

Name Type Description
scene Strawberry.Core.Scene
instantiateAssets Strawberry.Core.AssetManager = null

CleanManaged protected override

void CleanManaged()