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

SpatialEntity.HasChanged

bool HasChanged(SpatialComponent components)

Did any of these components change this frame? Like Changed, this resets every frame, so check it each frame.

   
SpatialComponent components One or more components to check.
RETURNS: bool True if any component given changed this frame.

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!