Skip to content

Game.SubReplacement

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: struct

Base: IBufferElementData, IEquatable, ISerializable

Summary: Represents a replacement entry for a networked sub-entity (a "sub" used by the game's Net system). This buffer element holds a reference to a prefab Entity plus small metadata about the replacement: the replacement type, the side, and an age mask. The struct is marked with InternalBufferCapacity(2), so buffers containing SubReplacement will be optimized for small counts (inlined up to 2 elements).


Fields

  • public Entity m_Prefab
    Represents the prefab Entity used for the replacement. This is a Unity.Entities.Entity that typically references a prefab entity used by the Net system.

  • public SubReplacementType m_Type
    Enum indicating the type of replacement. Serialized as a single byte when writing.

  • public SubReplacementSide m_Side
    Enum (stored as signed byte in serialization) indicating which side the replacement applies to (e.g., left/right or similar concept used by the Net system).

  • public AgeMask m_AgeMask
    Mask or small enum representing age categories that this replacement applies to. Serialized as a single byte.

Properties

  • (none)
    This struct exposes no C# properties; it uses public fields and implements interfaces directly.

Constructors

  • public SubReplacement()
    No explicit constructor is defined in source—this is the implicit default value-type constructor which initializes the fields to their default values (Entity = Entity.Null, enums = 0).

Methods

  • public bool Equals(SubReplacement other)
    Compares this instance to another SubReplacement. Returns true when m_Prefab, m_Type, m_Side and m_AgeMask are all equal. Note: Equality is strict on the prefab Entity reference and all metadata fields.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the struct to the provided writer. Serialization layout:

  • m_Prefab written as an Entity
  • m_Type written as a byte
  • m_Side written as a signed byte
  • m_AgeMask written as a byte

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes values from the provided reader into this struct. Reads in the same order as Serialize:

  • reads Entity into m_Prefab
  • reads byte into m_Type
  • reads sbyte into m_Side
  • reads byte into m_AgeMask

Usage Example

// Example: adding a SubReplacement to a dynamic buffer on an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity myEntity = entityManager.CreateEntity();

// Ensure the entity has a dynamic buffer for SubReplacement
if (!entityManager.HasComponent<SubReplacement>(myEntity))
    entityManager.AddBuffer<SubReplacement>(myEntity);

// Get the buffer and add a replacement
var buffer = entityManager.GetBuffer<SubReplacement>(myEntity);
var replacement = new SubReplacement
{
    m_Prefab = prefabEntity,          // an Entity reference to the prefab
    m_Type = SubReplacementType.SomeType,
    m_Side = SubReplacementSide.Left,
    m_AgeMask = AgeMask.AllAges
};
buffer.Add(replacement);

// Note: this struct implements ISerializable for custom binary read/write,
// so network or save systems can call Serialize/Deserialize with their writers/readers.
// The buffer has an [InternalBufferCapacity(2)] attribute: small buffers (<=2) are inlined.