# Update Entity

**URL:** <https://community.cesium.com/t/update-entity/6423>\
**Category:** CesiumJS\
**Created:** [January 2, 2018, 3:45pm UTC](https://community.cesium.com/t/update-entity/6423 "2018-01-02T15:45:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![naresh3591](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@naresh3591](https://community.cesium.com/u/naresh3591)\
**Post date:** [January 2, 2018, 3:45pm UTC](https://community.cesium.com/t/update-entity/6423/1 "2018-01-02T15:45:03Z")

</div>

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.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.entities.remove(entity);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.entities.remove(entity);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.setTimeout(function(){  
&nbsp;&nbsp;&nbsp;&nbsp;entities.add(entity);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},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.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.entities.remove(entity);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [January 2, 2018, 9:00pm UTC](https://community.cesium.com/t/update-entity/6423/2 "2018-01-02T21:00:21Z")

</div>

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**](https://cesiumjs.org/Cesium/Build/Documentation/EntityCollection.html#collectionChanged)event which you can subscribe to. It will be raised after the entity has been removed from the list.

Thanks,

Gabby

---

<div class="post-metadata">

**Author:** ![naresh3591](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@naresh3591](https://community.cesium.com/u/naresh3591)\
**Post date:** [January 3, 2018, 6:59am UTC](https://community.cesium.com/t/update-entity/6423/3 "2018-01-03T06:59:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [January 3, 2018, 9:13pm UTC](https://community.cesium.com/t/update-entity/6423/4 "2018-01-03T21:13:39Z")

</div>

When I went to create an example, I actually could not duplicate. [Here](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=f1fdd9ba3fb77b845ea14833208821b9) is my working example with add/remove.

Could you provide a code snippet so I can duplicate?

Thanks,

Gabby
