Game.Objects.Moving
Assembly:
{{ Likely Assembly-CSharp (default runtime assembly for game code); confirm in your project if different. }}
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Component that stores an object's linear and angular velocity for the Entities/ECS system. Implements custom binary serialization/deserialization and performs a safety check on deserialized values, resetting them to zero if any component is non-finite (NaN or Infinity). Also usable as a query type parameter for Entity query shorthand.
Fields
-
public Unity.Mathematics.float3 m_Velocity
{{ Linear velocity vector (x, y, z) for the object. Written first during serialization and read first during deserialization. }} -
public Unity.Mathematics.float3 m_AngularVelocity
{{ Angular velocity vector (x, y, z). Written second during serialization and read second during deserialization. }}
Properties
- None
{{ The struct exposes no properties — only public fields. It implements IComponentData so it is stored directly on entities. }}
Constructors
public Moving()
(implicit default)
{{ No explicit constructors are declared in the source; the default parameterless constructor is used. Initialize fields by assignment or via object initializer when creating component data. }}
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
{{ Writes m_Velocity then m_AngularVelocity to the provided writer in that order. Uses the writer's Write(float3) overload to serialize each vector. This is used by the game's save/load or network serialization systems that use the Colossal.Serialization.Entities abstractions. }} -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
{{ Reads m_Velocity then m_AngularVelocity from the provided reader into the struct's fields (reads by ref). After reading it validates both vectors by checking math.all(math.isfinite(...)). If either vector contains a non-finite component, both m_Velocity and m_AngularVelocity are reset to default(float3) (zero). This prevents NaN/Infinity propagation. }}
Usage Example
using Unity.Entities;
using Unity.Mathematics;
using Game.Objects;
// Create and assign the component to an entity
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity(typeof(Moving));
em.SetComponentData(e, new Moving {
m_Velocity = new float3(10f, 0f, 0f),
m_AngularVelocity = new float3(0f, 0.5f, 0f)
});
// Example: reading component in a system
public partial struct MovementSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
var emLocal = state.EntityManager;
Entities.ForEach((ref Moving mv) =>
{
// use mv.m_Velocity / mv.m_AngularVelocity for movement logic
}).Run();
}
}
{{Notes: The serialization methods rely on the Colossal.Serialization.Entities IWriter/IReader interfaces used by the game's modding/save system. When creating or modifying this component, ensure values are valid floats to avoid the automatic zeroing behavior on deserialize.}}