Prefab
A recipe for entities: a set of component values that belongs to no world, so no query ever sees it.
public sealed class PrefabA recipe for entities: a set of component values that belongs to no world, so no query ever sees it. World.Instantiate creates an entity with a copy of every value, in any world. Build it once (from code or configuration) and keep it; one prefab may serve worlds on several threads as long as nobody changes it meanwhile.
A prefab may have members (Prefab.AddMember): a boss with its minions and its mount. Instantiating any of them creates the whole group, and an EntityId field that names a member (Prefab.Id, for example new ChildOf(boss.Id)) names that member's new entity, any other is EntityId.Null: ids in a prefab name members only (an id of a world's entity may equal a member's). An Entity field is copied as it is: set relations to a world's entities after instantiating.
Constructors
Prefab
public Prefab();An empty recipe. O(1); allocates its private store once.
Prefab
public Prefab(Prefab basePrefab);A prefab with a copy of every value of basePrefab (and of its members), to change on its own: a variant of a configured NPC. Later changes of either prefab do not reach the other (a copy, no inheritance). O(components).
Properties
Id
public EntityId Id { get; }The id that names this member in the components of the group (rewritten on every instance).
Methods
AddMember
public Prefab AddMember();A new member of this prefab's group, without components: instantiating the prefab or any member creates every member. O(1).
Complexity (API table): O(1)
Has
public bool Has<T>() where T : struct, IComponent;Whether the prefab has component T.
Complexity (API table): O(1)
Read
public ref readonly T Read<T>() where T : struct, IComponent;The prefab's value of T; throws if it has none (change it with Set).
Complexity (API table): O(1)
Remove
public Prefab Remove<T1>() where T1 : struct, IComponent;
public Prefab Remove<T1, T2>() where T1 : struct, IComponent where T2 : struct, IComponent;
public Prefab Remove<T1, T2, T3>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4, T5>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4, T5, T6>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4, T5, T6, T7>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4, T5, T6, T7, T8>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public Prefab Remove<T1, T2, T3, T4, T5, T6, T7, T8, T9>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Drop 2 components from the recipe; missing components are ignored. Returns this prefab. O(2).
Complexity (API table): O(n)
Set
public Prefab Set<T1>(in T1 c1) where T1 : struct, IComponent;
public Prefab Set<T1, T2>(in T1 c1, in T2 c2) where T1 : struct, IComponent where T2 : struct, IComponent;
public Prefab Set<T1, T2, T3>(in T1 c1, in T2 c2, in T3 c3) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4>(in T1 c1, in T2 c2, in T3 c3, in T4 c4) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4, T5>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4, T5, T6>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4, T5, T6, T7>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4, T5, T6, T7, T8>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7, in T8 c8) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public Prefab Set<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7, in T8 c8, in T9 c9) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Add 2 components to the recipe, or replace their values. Returns this prefab (chain calls). O(2).
Complexity (API table): O(n), or O(c) amortized when it gains a component
SetBuffer
public Prefab SetBuffer<T>(params ReadOnlySpan<T> elements) where T : struct;Gives the prefab a DynamicBuffer of elements, replacing the one it has: every instance gets a list of its own with these elements. Returns the prefab. O(n).
Complexity (API table): O(n)
Last updated on
How is this guide?