Skip to content

Game.Prefabs.SpawnableObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a spawnable prefab component used by the game's prefab system. Holds one or more placeholder object prefabs that can be spawned, an overall spawn probability, and an optional randomization group. The component provides dependency reporting for the prefab loader and declares the ECS component type required at runtime (SpawnableObjectData).


Fields

  • public ObjectPrefab[] m_Placeholders
    Holds an array of object prefabs that act as placeholders (possible variants) for this spawnable object. These are added as dependencies in GetDependencies so they will be loaded with the parent prefab.

  • public int m_Probability
    Annotated with [Range(0f, 100f)]. Represents the probability (0–100) that this object will be placed/spawned. Default value in the class is 100.

  • public GroupPrefab m_RandomizationGroup
    Optional reference to a GroupPrefab used for randomization. If assigned, the group is added to the prefab dependencies so it is available at runtime.

Properties

  • None (this class does not declare any C# properties)

Constructors

  • public SpawnableObject()
    Implicit default constructor. The class relies on serialized field values populated by Unity/prefab data; no custom constructor logic is defined.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Collects and reports prefab dependencies needed by this component. Implementation:
  • Calls base.GetDependencies(prefabs).
  • Adds every entry in m_Placeholders to the provided prefabs list.
  • If m_RandomizationGroup is not null, adds it to the prefabs list. Use: ensures referenced placeholders and randomization group are loaded along with the parent prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required ECS component types for this prefab to the provided set. Implementation:

  • Adds ComponentType.ReadWrite() to indicate that entities created from this prefab require the SpawnableObjectData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Declared but empty in this class. No additional archetype components are added by this component at prefab creation time.

Usage Example

// Typical runtime usage: read configuration from the component on a loaded prefab instance
var spawnable = gameObject.GetComponent<Game.Prefabs.SpawnableObject>();
if (spawnable != null)
{
    var placeholders = spawnable.m_Placeholders; // ObjectPrefab[]
    int probability = spawnable.m_Probability;   // 0-100

    // Example: iterate placeholders
    foreach (var p in placeholders)
    {
        Debug.Log($"Placeholder prefab: {p?.name}");
    }
}

{{ Additional notes: - This component is intended to be attached to prefab assets (not regular runtime-only GameObjects) so its serialized fields are used by the prefab system. - The presence of ComponentType.ReadWrite() in GetPrefabComponents means prefabs with this component expect corresponding ECS data; ensure your systems handle SpawnableObjectData. - m_Probability is serialized as an int but uses a Range attribute with float literal bounds; the effective allowed values are 0 through 100. }}