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

SpatialEntity.Removed

static SpatialEntityCollection Removed{ get }

Description

An enumeration of the spatial entities leaving the entity list this frame, because they were lost by the system, destroyed, or Status Failed. Lost persisted entities don’t leave, they wait to load again. These are still Valid with readable data for this one frame, which makes this the place to clean up anything you’ve cached per-entity!

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!