public void RemoveEntity(VMEntity entity)
{
if (Entities.Contains(entity))
{
Context.SetToNextCache.RemoveObject(entity);
this.Entities.Remove(entity);
ObjectsById.Remove(entity.ObjectID);
if (entity.ObjectID < ObjectId) ObjectId = entity.ObjectID; //this id is now the smallest free object id.
}
entity.Dead = true;
}