Game.Simulation.WaterPipeValveConnection
Assembly: Assembly-CSharp (game code)
Namespace: Game.Simulation
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
A lightweight ECS component that links a water-pipe entity to a valve node entity in the water simulation. The component stores a single Entity reference (m_ValveNode). It implements ISerializable so the reference is written to and restored from the game's serialization stream during save/load. Use this component on entities that need to know which valve node they are connected to in the pipe/valve network.
Fields
public Entity m_ValveNode
Holds the Entity reference to the valve node this pipe/connection is associated with. When no valve is connected use Entity.Null. During serialization the Entity is written through the IWriter and will be remapped on load by the engine's entity remapping logic.
Properties
- (none)
This struct exposes no properties — only the public field m_ValveNode.
Constructors
public WaterPipeValveConnection()
Default value-type constructor (implicit). You can initialize an instance with a specific valve entity by using object initializer syntax: var c = new WaterPipeValveConnection { m_ValveNode = valveEntity };
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_ValveNode Entity to the provided writer. Used by the game's save system to persist the connection. The writer implementation is responsible for correctly recording entity references so they can be remapped on load. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Entity reference from the provided reader into m_ValveNode. Called during load to restore the previously saved valve node reference (subject to entity remapping).
Usage Example
using Unity.Entities;
using Game.Simulation;
// Add a connection component to a pipe entity, pointing to a valve entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity pipeEntity = /* obtain/create pipe entity */;
Entity valveEntity = /* obtain/create valve node entity */;
var connection = new WaterPipeValveConnection { m_ValveNode = valveEntity };
em.AddComponentData(pipeEntity, connection);
// Later, read the valve entity
var stored = em.GetComponentData<WaterPipeValveConnection>(pipeEntity);
Entity linkedValve = stored.m_ValveNode;
if (linkedValve != Entity.Null)
{
// operate on valve entity...
}
Notes and tips: - Use Entity.Null to represent “no valve connected.” - Because the component implements ISerializable, you generally do not need to handle the low-level save/load of the Entity yourself — the game's serialization system will call Serialize/Deserialize and remap entity IDs as appropriate. - Keep this component small and data-only so it remains safe to use in jobs and ECS systems.