Skip to content

Game.Prefabs.SpawnableObjectData

Assembly: Assembly-CSharp.dll (typical Unity project)
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
SpawnableObjectData is a lightweight ECS component used to mark an entity as a spawnable object and to provide weight/probability information for randomized selection. Typically used by spawn/prefab randomization systems: entities are grouped by a "randomization group" (another Entity) and the m_Probability field is used as the selection weight within that group. This struct contains no behavior — only data consumed by systems at runtime.


Fields

  • public Unity.Entities.Entity m_RandomizationGroup
    An Entity used to group spawnable entries together for randomized selection. Systems can query all entities that share the same m_RandomizationGroup and choose among them according to their m_Probability values. Use Entity.Null to indicate "no group" if appropriate.

  • public int m_Probability
    The integer weight or probability used when selecting among spawnables in the same group. Interpreted as a relative weight (e.g., a value of 2 is twice as likely as a value of 1). Non-positive values typically mean "never selected" or have no weight; concrete behavior depends on the consuming system. Keep values non-negative and consider the sum of weights when implementing selection.

Properties

  • This struct exposes no C# properties; it only contains the two public fields above.

Constructors

  • public SpawnableObjectData()
    Structs in C# have an implicit parameterless constructor. By default m_RandomizationGroup will be Entity.Null and m_Probability will be 0. You can initialize using object initializer syntax: new SpawnableObjectData { m_RandomizationGroup = someEntity, m_Probability = 10 }

Methods

  • This type declares no methods. It is a plain data container (IComponentData) intended to be read by ECS systems. The IQueryTypeParameter implementation marker is used for query typing and has no additional methods here.

Usage Example

// Example: adding SpawnableObjectData to an entity (EntityManager API)
var spawnable = new SpawnableObjectData {
    m_RandomizationGroup = randomGroupEntity,
    m_Probability = 5
};
entityManager.AddComponentData(targetEntity, spawnable);

// Example usage idea inside a system:
// - Query all entities with SpawnableObjectData filtered by a specific m_RandomizationGroup
// - Sum m_Probability values, pick a random value in [0, sum) and select the corresponding entity
// (Selection logic is implemented in the spawning system, not in this data struct.)