Skip to content

Game.Prefabs.SubObject

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
Represents a single child/sub-object entry used by a prefab. This struct is an IBufferElementData and is intended to be stored in a dynamic buffer on a prefab entity (InternalBufferCapacity(0) is applied, so the buffer starts empty). Each element points to another prefab Entity and contains local transform, grouping and spawning information used by the prefab instantiation/placement systems (e.g., hierarchical placement, random selection, visibility/behavior flags).


Fields

  • public Entity m_Prefab
    Reference to the Entity that should be instantiated as the sub-object. Typically points to another prefab entity (mesh/LOD/child object).

  • public SubObjectFlags m_Flags
    Bitflags that control sub-object behavior (visibility, physics, shadowing, attachment rules, etc.). The exact flag values are defined by the SubObjectFlags enum in the codebase — check that enum for the specific semantics of each flag.

  • public float3 m_Position
    Local position of the sub-object relative to the parent prefab or the anchor point. Uses Unity.Mathematics.float3.

  • public quaternion m_Rotation
    Local rotation of the sub-object relative to the parent prefab or anchor. Uses Unity.Mathematics.quaternion.

  • public int m_ParentIndex
    Index of the parent sub-object within the same dynamic buffer (or a sentinel such as -1 if there is no parent). Used to construct hierarchical relationships between subobjects.

  • public int m_GroupIndex
    Group identifier used for grouping sub-objects together (for example, to apply group-based LOD, toggling, or selection rules).

  • public int m_Probability
    An integer weight or probability value used by spawning/randomization logic to influence which sub-object variant will be chosen. Interpretation (absolute weight vs percentage) depends on the prefab spawning implementation.

Properties

  • This struct exposes no properties. It is a plain IBufferElementData value type with public fields.

Constructors

  • public SubObject()
    No explicit constructor is defined in source — the default value-type constructor applies and will zero/none-initialize all fields. Initialize fields explicitly before using.

Methods

  • This struct defines no methods.

Usage Example

// Example: add sub-objects buffer to a prefab entity and push entries.
// Assumes 'entityManager' or an EntityCommandBuffer ecb, and 'prefabEntity' exist.

var buffer = entityManager.AddBuffer<Game.Prefabs.SubObject>(prefabEntity);

// Create a sub-object entry
Game.Prefabs.SubObject sub = default;
sub.m_Prefab = someChildPrefabEntity;
sub.m_Flags = SubObjectFlags.None; // set appropriate flags
sub.m_Position = new float3(0f, 1.0f, 0f);
sub.m_Rotation = quaternion.identity;
sub.m_ParentIndex = -1; // no parent
sub.m_GroupIndex = 0;
sub.m_Probability = 100; // weight

buffer.Add(sub);

Notes and recommendations: - The meaning of SubObjectFlags, valid values for m_ParentIndex, and the scale/units of m_Probability are governed by other parts of the prefab/pooling/spawning systems — inspect those enums and systems before changing behavior. - Because InternalBufferCapacity is 0, buffers of this type begin empty and will allocate on first use; be mindful of allocations in hot code paths.