Game.Objects.Attached
Assembly:
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents an attachment relationship between two entities with a position along a curve. Used as a component to mark that an entity is attached to a parent entity, optionally remembering a previous parent and a float "curve position" value. Implements Colossal's ISerializable to persist the parent and curve position.
Fields
-
public Entity m_Parent
Holds the Entity reference for the current parent. This is the value written and read during serialization/deserialization. -
public Entity m_OldParent
Holds the Entity reference for the previous parent. Note: this field is not serialized by the provided Serialize/Deserialize implementation, so it will not be preserved across save/load unless handled separately. -
public float m_CurvePosition
Float representing the position along a curve (or similar normalized/relative position). This value is serialized and restored by Deserialize.
Properties
- None. (This struct exposes only public fields; it does not declare properties.)
Constructors
public Attached(Entity parent, Entity oldParent, float curvePosition)
Initializes a new Attached instance with the supplied parent, old parent, and curve position values.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes component data to the provided writer. Implementation writes the current parent entity followed by the curve position. Note: m_OldParent is not written. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from the provided reader. Implementation reads into m_Parent and m_CurvePosition. m_OldParent is not read and will remain default unless set elsewhere.
Usage Example
// Create an Attached instance and add it to an entity using the EntityManager
Entity parentEntity = /* obtain parent entity */;
Entity oldParentEntity = /* previous parent, or Entity.Null */;
Entity childEntity = /* the entity to attach */;
var attached = new Attached(parentEntity, oldParentEntity, 0.5f);
entityManager.AddComponentData(childEntity, attached);
// Example: serializing the component (pseudocode, depends on actual writer implementation)
using (var writer = new SomeConcreteWriter(stream))
{
attached.Serialize(writer);
}
// Example: deserializing back into a component (pseudocode)
Attached loaded = default;
using (var reader = new SomeConcreteReader(stream))
{
loaded.Deserialize(reader);
}
entityManager.SetComponentData(childEntity, loaded);
{{ - Notes & Tips: - Because m_OldParent is not serialized, the previous-parent information will be lost across saves/loads unless you extend the serialization methods to include it. - This struct is intended for use within Unity's DOTS/ECS context (IComponentData) and Colossal's serialization system (IWriter/IReader). - Be careful when serializing Entity references: ensure the serialization system you use correctly remaps entity IDs across save/load boundaries (Colossal's entity serialization helpers usually handle this). }}