Skip to content

Game.Prefabs.CreaturePrefab

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: MovingObjectPrefab

Summary:
CreaturePrefab is a prefab definition for creature-type moving objects used by the game's ECS-based instantiation systems. It exposes a gender mask (m_Gender) used to limit or indicate allowed genders for this prefab, and it ensures that the correct ECS components are registered both on the prefab and on the runtime archetype. The class is annotated with Unity's ComponentMenu attribute so it can be created/selected via the Unity editor menu under "Creatures/".


Fields

  • public GenderMask m_Gender = GenderMask.Any
    Used to indicate which genders are valid for this creature prefab. Defaults to GenderMask.Any. This field is usually editable in the inspector and can be used by creature-spawning logic to filter or set gender on created entities.

Properties

  • This class does not declare any public properties.

Constructors

  • public CreaturePrefab()
    No explicit constructor is defined in the source; the default parameterless constructor is provided by the compiler. Initialization of prefab-relevant runtime state is done via the class methods / Unity inspector rather than a custom constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds component types that should exist on the prefab representation (asset-level). This override calls the base implementation (MovingObjectPrefab) and then adds:
  • ComponentType.ReadWrite<CreatureData>()
    CreatureData typically contains prefab-level metadata required for creature instantiation or editor configuration.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that should be part of the runtime ECS archetype created when entities are instantiated from this prefab. This override calls the base implementation and then adds:

  • ComponentType.ReadWrite<Creature>() — runtime marker/state for a creature entity
  • ComponentType.ReadWrite<Color>() — color information for the creature (appearance)
  • ComponentType.ReadWrite<Surface>() — surface/navigation/ground relation for movement/placement

These methods ensure the prefab and resulting runtime entities contain the minimal required data for creature behaviour and rendering.

Usage Example

// Create a custom prefab that adds an extra ECS component to creatures
using System.Collections.Generic;
using Unity.Entities;
using Game.Prefabs;

public class MyCreaturePrefab : CreaturePrefab
{
    // Set default gender in code (also editable in Inspector)
    public MyCreaturePrefab()
    {
        m_Gender = GenderMask.Female;
    }

    public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {
        base.GetArchetypeComponents(components);

        // Add a custom component type to the creature archetype
        components.Add(ComponentType.ReadWrite<MyCustomBehavior>());
    }
}

Notes and tips: - The ComponentMenu attribute on the original class places it under "Creatures/" in Unity's Add Component menu, making it easy to create prefab assets via the editor. - When adding custom components in overrides, always call base.GetPrefabComponents / base.GetArchetypeComponents first to preserve the base prefab requirements. - The component types added here (CreatureData, Creature, Color, Surface) are required by the game's creature systems — omitting them may cause runtime errors or missing behaviour.