Skip to content

Game.Prefabs.CharacterProperties

Assembly: (unspecified)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component attached to character prefabs that describes which body parts the prefab contains, references to corrective/animated prop names, and an ordered list of CharacterOverlay prefabs. During prefab late-initialization it translates the CharacterOverlay array into a DynamicBuffer on the instantiated entity (resolving overlay prefabs to entities via PrefabSystem). This component is used by the rendering/character pipeline to know which overlays to create and how to sort them.


Fields

  • public BodyPart m_BodyParts
    Flags indicating which body parts this character prefab provides. Useful for combining or overriding parts at runtime (torso, head, face, legs, feet, beard, neck).

  • public string m_CorrectiveAnimationName
    Optional name of a corrective animation to apply to this prefab (string identifier).

  • public string m_AnimatedPropName
    Optional name of an animated prop associated with the character prefab.

  • public CharacterOverlay[] m_Overlays
    Array of CharacterOverlay prefabs describing overlay elements (e.g., clothing, accessories). Used in LateInitialize to populate the entity's OverlayElement buffer.

  • public enum BodyPart
    Nested [Flags] enum describing body part bits:

  • Torso = 1
  • Head = 2
  • Face = 4
  • Legs = 8
  • Feet = 0x10
  • Beard = 0x20
  • Neck = 0x40

Properties

  • (none declared)
    This class declares no C# properties. All data is exposed as public fields.

Constructors

  • public CharacterProperties()
    Default parameterless constructor (implicitly provided). No custom construction logic in the source.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds dependent prefabs to the provided list. Implementation adds each element of m_Overlays (if any) to the dependency list so the overlay prefabs are loaded/available before this prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty in this implementation — this component does not add any ECS archetype components directly at this stage.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    If m_Overlays is non-null/non-empty, adds ComponentType.ReadWrite() to the components set. This ensures prefab entities get a DynamicBuffer for overlays.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called during prefab/entity finalization. For non-empty m_Overlays it:

  • Obtains the PrefabSystem from the World to resolve overlay prefabs to entities.
  • Gets the DynamicBuffer for the entity.
  • Computes the required buffer size based on the maximum overlay m_Index + 1.
  • Resizes the buffer (clearing memory) and fills entries using the CharacterOverlay array: sets m_Overlay to the resolved entity and m_SortOrder from the CharacterOverlay. This wiring makes overlay entities accessible at runtime via the OverlayElement buffer.

Usage Example

// Example: typical usage happens via prefab authoring in the editor.
// CharacterProperties is added to a Render prefab and configured with CharacterOverlay references.
// During prefab instantiation the engine calls LateInitialize, which populates the OverlayElement buffer.

[ComponentMenu("Rendering/", new Type[] { typeof(RenderPrefab) })]
public class CharacterProperties : ComponentBase
{
    public CharacterOverlay[] m_Overlays;
    public BodyPart m_BodyParts;
    public string m_CorrectiveAnimationName;
    public string m_AnimatedPropName;

    // The engine will call LateInitialize(entityManager, entity) so overlays are resolved to entity references.
}

Notes and implementation details: - CharacterOverlay, OverlayElement and PrefabSystem are other engine types: CharacterOverlay is a PrefabBase-derived asset that includes at least m_Index and m_SortOrder fields; OverlayElement is a buffer element struct with m_Overlay (Entity) and m_SortOrder. - LateInitialize uses NativeArrayOptions.ClearMemory when resizing the buffer to ensure deterministic default values. - GetArchetypeComponents intentionally does nothing; any additional ECS components required by overlays are provided via GetPrefabComponents and/or other systems.