Update Entity

1. A concise explanation of the problem you're experiencing.

Hi Cesium Team,

I am new to Cesium and had a situation where I need to update the entity, so for this I am removing the entity and then adding again.
              
            1.entities.remove(entity);
            2.entities.add(entity);

But before completion of statement 1, statement 2 is executing so I am getting an error : An entity with the id already exists in the collection. Do we have any solution for this ?

If add timeout it is working, but this not sure will always it works

            1.entities.remove(entity);
            2.setTimeout(function(){
    entities.add(entity);
        },1000);

Do we have any call back function for remove entity?

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

            1.entities.remove(entity);
            2.entities.add(entity);

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

To update the entity.

4. The Cesium version you're using, your operating system and browser.

1.22.1 , Windows, Chrome

Hi there,

The remove function marks an entity for deletion, but does not remove it from the list until the next update of the collection, which happens each render frame.

There’s the EntityCollection.collectionChanged event which you can subscribe to. It will be raised after the entity has been removed from the list.

Thanks,

Gabby

Can you please provide any sample example for subscribing collection changed event.

When I went to create an example, I actually could not duplicate. Here is my working example with add/remove.

Could you provide a code snippet so I can duplicate?

Thanks,

Gabby