Skip to content

Game.Prefabs.SubObjectDefaultProbability

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component intended for object prefabs that provides a default placement probability for placeable sub-objects. When present on a prefab this component ensures the prefab's PlaceableObjectData component is present and sets its default probability, rotation symmetry and placement flags. It will report an error if placed on a prefab that also contains a ServiceUpgrade component.


Fields

  • public int m_DefaultProbability
    Range: 0–100 (decorated with [Range(0f, 100f)]). Default value in code: 100. This value is written into the prefab's PlaceableObjectData.m_DefaultProbability (cast to byte) during initialization.

  • public RotationSymmetry m_RotationSymmetry
    Defines the rotation symmetry for the placeable object; assigned to PlaceableObjectData.m_RotationSymmetry during initialization.

Properties

  • None (no public properties defined by this component).

Constructors

  • public SubObjectDefaultProbability()
    Implicit default constructor. The field defaults are: m_DefaultProbability = 100, m_RotationSymmetry = (default value of RotationSymmetry).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components) : System.Void
    Adds ComponentType.ReadWrite() to the provided set so the prefab system knows the prefab requires PlaceableObjectData.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components) : System.Void
    Empty override — this component does not declare additional archetype components at this point.

  • public override void Initialize(EntityManager entityManager, Entity entity) : System.Void
    Called during prefab initialization. Behavior:

  • Calls base.Initialize(...).
  • If the prefab contains a ServiceUpgrade component, logs an error (ServiceUpgrade cannot have SubObjectDefaultProbability).
  • Retrieves the PlaceableObjectData for the entity and sets:
    • m_DefaultProbability = (byte)m_DefaultProbability (value from this component).
    • m_RotationSymmetry = this.m_RotationSymmetry.
    • Sets the PlacementFlags.HasProbability flag on PlaceableObjectData.m_Flags.
  • Writes the modified PlaceableObjectData back to the entity.

Remarks: - The integer m_DefaultProbability is clamped by the Range attribute in the inspector (0–100) and is explicitly cast to byte when stored in PlaceableObjectData, so overflow is not expected given the range. - This component relies on types: PlaceableObjectData, PlacementFlags, ServiceUpgrade, RotationSymmetry, and Unity.Entities (EntityManager/Entity).

Usage Example

// After prefab initialization (conceptual example)
PlaceableObjectData data = entityManager.GetComponentData<PlaceableObjectData>(entity);
// Assuming the prefab had a SubObjectDefaultProbability component with m_DefaultProbability == 80:
Debug.Assert(data.m_DefaultProbability == (byte)80);
Debug.Assert((data.m_Flags & PlacementFlags.HasProbability) != 0);