> For the complete documentation index, see [llms.txt](https://plugins.jbsnippets.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plugins.jbsnippets.com/my-plugins/unique-id-node.md).

# Unique ID Node

This node can be added as a child of an existing node. The parent node will then have its name either concatenated with the ID or replaced by the ID.

## Features

* Can generate 3 different length of unique ID: Short, Medium, Long.
* Ability to concatenate the ID to parent name or replace the parent name.
* Option to add a string separator when concatenating the ID.
* Option to set the unique ID as persistent (saved to disk).
* Automatically free this custom node after generating the unique ID.

## How the idea started

*"I was trying to search my node tree for a code-generated node, but I struggled because all the names were identical, labeled as @StaticBody\@. I thought, why not retain the original name I gave each node and simply append some random characters to avoid any name clashes? And that's how the Unique ID node was born."*

Here’s a video showcasing the initial development of the plugin.

{% embed url="<https://www.youtube.com/watch?v=Orj3tYSlQsc>" %}
Creating my first plugin in Godot
{% endembed %}

## How to use

#### Adding the Node

After enabling this plugin, you can add the `UniqueId` node as a child of another node and it will add or replace a Unique ID to the parent node.

1. Right-click on a node or press Ctrl+A.

   <div align="left"><figure><img src="/files/jW9AF37NorvY43n9ou5L" alt=""><figcaption><p>Adding a new node</p></figcaption></figure></div>
2. Type "unique" on the Search textbox of the Create New Node form to filter the node list and easily find the `UniqueId` node.

   <div align="left"><figure><img src="/files/HRBuvRmsYdS12RdiEQmh" alt=""><figcaption><p>Searching the UniqueId node</p></figcaption></figure></div>
3. Double-click the `UniqueId` node to add as a child of the node.

   <div align="left"><figure><img src="/files/lC8L6hXS2PazpFHI7DDz" alt=""><figcaption><p>UniquId node as a child node</p></figcaption></figure></div>

{% hint style="info" %}
Adding more than one `UniqueId` node will result in creating a sequence of Unique IDs. The IDs will either be concatenated or replace the parent name, which ever comes first.
{% endhint %}

{% hint style="warning" %}
Adding the `UniqueId` node as the only node, or a child of the root node, will result in changing the name of the root node.
{% endhint %}

#### Variables in Inspector

* **Length**: The length of the unique ID to generate.
  * ***Short***: When selected, the node will generate a 4 hexadecimal ID (8 characters).
  * ***Medium***: When selected, the node will generate an 8 hexadecimal ID (16 characters).
  * ***Long***: When selected, the node will generate a 16 hexadecimal ID in UUID format (36 characters including dash).
* **Separator**: The string separator between the original node name and unique ID. Not used when `Replace Original` is true.
* **Enabled**: Property to enable/disable the node.
* **Replace Original**: When enabled, the parent's name is replaced by the generated unique ID.
* **Persistent Id**: When enabled, the unique ID is saved in disk along with the object's instance ID. The file that stores the instance ID to unique ID mapping is saved in `user://persistent.ids`.&#x20;

{% hint style="info" %}
To save the unique IDs, call `PersistentId.save_ids()`, preferably in the `_ready` function of the root node.
{% endhint %}

{% hint style="info" %}
To remove the unique ID from the list in the `persistent.ids` file, disable the **Persistent Id** option.
{% endhint %}

{% hint style="warning" %}
I recommend **only use persistent IDs on static nodes**.

When using persistent IDs with dynamically created nodes, the plugin will always perform a save and load of unique IDs, as the node's instance ID changes each time the dynamic node is created.

The primary use-case for the plugin is to add unique IDs to defined node names, facilitating easy searching and filtering during game debugging.&#x20;

Use persistence moderately, as excessive persistence can negatively impact performance.
{% endhint %}

#### Examples

Without using the `UniqueId` node.

<div align="left"><figure><img src="/files/23CRvvYuHLoHoOy1plyg" alt=""><figcaption></figcaption></figure></div>

When using the `UniqueId` node.

<div align="left"><figure><img src="/files/7pIJBEdBRXM8giN2Zlzi" alt=""><figcaption></figcaption></figure></div>

Easier to search and filter!

<div align="left"><figure><img src="/files/zqg2ydA8SC40VmUgU5So" alt=""><figcaption></figcaption></figure></div>

## More Screenshots

<figure><img src="/files/cdKDeaViqjVVBks9exEO" alt=""><figcaption><p>UniqueId inspector panel</p></figcaption></figure>

<figure><img src="/files/tJVfXlxfEmI7RDpRb7TL" alt=""><figcaption><p>UniqueId documentation</p></figcaption></figure>
