⚠ Preview docs — built from the develop branch and may be unstable. Go to the stable docs.

SpatialEntity.Changed

SpatialComponent Changed{ get }

Description

Components whose data meaningfully changed this frame! Continuously updating poses are only flagged when they first arrive, while mesh/polygon/marker data is flagged whenever the system provides new data. Handy for skipping expensive work like mesh extraction when nothing changed. These flags reset every frame, so check them each frame or you may miss an update.

Examples

Keeping a mesh for each plane

Filling a Mesh isn’t free, so this only refills when the plane’s shape changes, and drops the mesh when the plane goes away.

Dictionary<SpatialEntity, Mesh> planeMeshes = new Dictionary<SpatialEntity, Mesh>();

public void StepPlaneMeshes()
{
	foreach (SpatialEntity plane in SpatialEntity.With(SpatialComponent.Mesh2D))
	{
		bool isNew = !planeMeshes.TryGetValue(plane, out Mesh mesh);
		if (isNew)
		{
			mesh = new Mesh();
			planeMeshes.Add(plane, mesh);
		}

		// A null mesh only fetches the origin, which moves every frame
		bool refill = isNew || plane.HasChanged(SpatialComponent.Mesh2D);
		plane.TryGetMesh2D(refill ? mesh : null, out Pose origin);
		mesh.Draw(Material.Default, origin.ToMatrix());
	}

	// Removed entities are still readable this frame, so clean up here
	foreach (SpatialEntity plane in SpatialEntity.Removed)
		planeMeshes.Remove(plane);
}




Found an issue with these docs, or have some additional questions? Create an Issue on Github!