Game.Objects.SubObject
Assembly:
Assembly-CSharp (runtime) — defined in the Game assembly portion of the project
Namespace:
Game.Objects
Type:
public struct SubObject
Base:
System.ValueType
Implements: Unity.Entities.IBufferElementData, System.IEquatable
Summary:
Represents a buffer element that holds a reference to a Unity.Entities.Entity used as a "sub-object" (child/linked object) for another entity. Marked with [InternalBufferCapacity(0)], so the buffer is stored out-of-line (no inline capacity). Equality and hash code are based on the contained Entity value.
Fields
public Unity.Entities.Entity m_SubObject
Holds the Entity reference for the sub-object. This is the value used for equality and hashing. Typical usage is to store child or associated entities in a DynamicBufferattached to a parent entity.
Properties
- (none)
Constructors
public SubObject(Unity.Entities.Entity subObject)
Creates a SubObject that wraps the provided Entity instance. Use this when adding entries to a DynamicBufferor when constructing the element manually.
Methods
-
public bool Equals(SubObject other)
Compares this element to another SubObject by comparing their m_SubObject Entity values. -
public override int GetHashCode()
Returns the hash code of the contained Entity (m_SubObject.GetHashCode()).
Usage Example
// Add a sub-object to a parent entity's buffer (EntityManager approach)
void AddSubObject(EntityManager entityManager, Entity parentEntity, Entity childEntity)
{
// Ensure the parent has a DynamicBuffer<SubObject>
if (!entityManager.HasComponent<SubObject>(parentEntity))
{
entityManager.AddBuffer<SubObject>(parentEntity);
}
var buffer = entityManager.GetBuffer<SubObject>(parentEntity);
buffer.Add(new SubObject(childEntity));
}
// Or using EntityCommandBuffer in a system
void AddSubObjectWithECB(EntityCommandBuffer ecb, Entity parentEntity, Entity childEntity)
{
var buffer = ecb.AddBuffer<SubObject>(parentEntity);
buffer.Add(new SubObject(childEntity));
}