Game.Objects.MovedLocation
Assembly:
Game
Namespace:
Game.Objects
Type:
struct
Base:
System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
Stores the previous/world position of an entity. Intended for use with Unity's ECS (DOTS) to track that an entity has moved and to provide its last known position for systems that need to react to movement (e.g., updating pathing, visuals, collision checks, or network/state synchronization in a Cities: Skylines 2 mod). The component is a simple, blittable value type (contains Unity.Mathematics.float3) and is safe for Burst and jobified usage.
Fields
public Unity.Mathematics.float3 m_OldPosition
Holds the entity's previous position (e.g., before a move or physics update). Use this to compare against the current position to determine displacement or to interpolate/rollback state.
Properties
- None.
This struct exposes a single public field and defines no properties.
Constructors
public MovedLocation()
No explicit constructor is declared in the source; the struct uses the default (parameterless) constructor provided by C#. You can also initialize the field directly when creating an instance: new MovedLocation { m_OldPosition = someFloat3 };
Methods
- None.
This is a pure data container component (IComponentData) and provides no behavior methods.
Usage Example
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Game.Objects;
// Example: add/update MovedLocation when moving an entity
public partial class ExampleMoveSystem : SystemBase
{
protected override void OnUpdate()
{
var em = EntityManager;
// Example: mark entities that moved this frame by adding/updating MovedLocation
Entities
.WithName("UpdateMovedLocation")
.ForEach((Entity entity, ref Translation trans) =>
{
// Suppose you determine the entity moved; capture the old position
// (In a real system you would compare against a stored position.)
float3 oldPos = trans.Value; // capture current as "old" before change
// Update component (adds if missing)
if (!em.HasComponent<MovedLocation>(entity))
{
em.AddComponentData(entity, new MovedLocation { m_OldPosition = oldPos });
}
else
{
em.SetComponentData(entity, new MovedLocation { m_OldPosition = oldPos });
}
}).Run();
}
}
Notes: - Because this is a simple value type component, it is efficient in jobs/Burst. Avoid storing managed types inside components. - Use EntityManager or dynamic buffer/system queries to add, read, or remove this component as entities move or when you no longer need the old-position data.