# Adding & Removing Elements

To add an entry into a scriptable dictionary is the same as adding an entry in a regular dictionary.&#x20;

In this example, each element prefab has a component "AddRemoveElementToDictionary" attached to it. Navigate to the hierarchy and select one element template object (you can choose any element, but I will show Water):

<figure><img src="https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2F7PpwnhrjTAtH2rzTYhhn%2Fimage.png?alt=media&#x26;token=3ac04082-1ebb-48cf-86be-06754faa1887" alt="" width="222"><figcaption></figcaption></figure>

Now, look in the inspector to check out its components:&#x20;

<figure><img src="https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2FSa32Kn84vYFR2pwpmaHo%2Fimage.png?alt=media&#x26;token=399c8377-90b4-40b3-a59c-fadf8f582b1f" alt="" width="375"><figcaption></figcaption></figure>

The nice part about using a Dictionary, is that we can have different cases when the item is already in the dictionary or not. Here is how an entry is added or removed:

```csharp
private void Start()
{
    _element = GetComponent<Element>();

    //Try to add the first element of this type
    if (!_scriptableDictionary.TryAdd(_element.ElementType, 1))
    {
        //If its already in, just increment the count
        _scriptableDictionary[_element.ElementType]++;
    }
}

private void OnDestroy()
{
    //Decrement the count of the element
    _scriptableDictionary[_element.ElementType]--;

    //If the count is 0, remove the element from the dictionary
    if (_scriptableDictionary[_element.ElementType] == 0)
    {
        _scriptableDictionary.Remove(_element.ElementType);
    }
}
```
