Skip to content

PrefabLibrary.TryInstantiate(string, IEntityWorld, Entity, Nullable, Nullable, Nullable, string) Method

Definition

Namespace: Brine2D.ECS

Attempts to instantiate a registered prefab by name.

C#
public bool TryInstantiate(string name, Brine2D.ECS.IEntityWorld world, out Brine2D.ECS.Entity? entity, System.Nullable<System.Numerics.Vector2> position=null, System.Nullable<float> rotation=null, System.Nullable<System.Numerics.Vector2> scale=null, string? entityName=null);

Parameters

name System.String

The registered prefab name.

world IEntityWorld

The world to create the entity in.

entity Entity

The instantiated entity, or null if the prefab was not found.

position System.Nullable<System.Numerics.Vector2>

Optional spawn position applied to the root TransformComponent.

rotation System.Nullable<System.Single>

Optional spawn rotation \(in radians\) applied to the root TransformComponent.

scale System.Nullable<System.Numerics.Vector2>

Optional spawn scale applied to the root TransformComponent.

entityName System.String

Optional override for the instantiated entity's name. When null \(default\), the prefab's own name is used. Pass an explicit value when spawning multiple instances so each entity can be found by name.

Returns

System.Boolean
true if the prefab was found and instantiated; otherwise false.