> 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

A custom Godot node that generates a unique ID to be concatenated to, or replace the parent node's name.

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="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2Fe5M9VtB1Km55s6ySdmOb%2Fadd_node0.png?alt=media&amp;token=e4a4fd6f-674a-4d58-bcd2-db15699b2269" 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="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2F2A401uXkMAhiI2WYYsIS%2Fadd_node.png?alt=media&amp;token=57b8c51a-89c3-4ee6-a2bc-a5671623d956" 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="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2FYrC00YDAj4hqSxlPEgy2%2Fadd_node2.png?alt=media&amp;token=7d6465e4-522e-4b71-8c9f-eb223ecd05c3" 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="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2FusJymiZ4iDXRLh1SYd90%2Fexample_1.png?alt=media&amp;token=10fc7265-aa8e-42ac-813a-2621df25c9f1" alt=""><figcaption></figcaption></figure></div>

When using the `UniqueId` node.

<div align="left"><figure><img src="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2FnDlTsjuReEm3Oue381hD%2Fexample_2.png?alt=media&amp;token=78307b3c-f537-4f68-a756-30fc7e306ca8" alt=""><figcaption></figcaption></figure></div>

Easier to search and filter!

<div align="left"><figure><img src="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2FK9zuWPQvq8TMrpdl0ubb%2Fexample_3.png?alt=media&amp;token=37591b36-c999-4ecf-8c3e-92807021a510" alt=""><figcaption></figcaption></figure></div>

## More Screenshots

<figure><img src="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2Fe26g6jHCE4aMUjazAOX4%2FScreenshot_2024-06-15_1.png?alt=media&amp;token=90bfdcfa-ab00-4fb0-9c0c-5ed7f46b3410" alt=""><figcaption><p>UniqueId inspector panel</p></figcaption></figure>

<figure><img src="https://2155394537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3nOGBFGEzfGtxNPH5Wmu%2Fuploads%2FerGmXuOuilNcEAlIMokj%2FScreenshot_2024-06-15_2.png?alt=media&amp;token=3b72091b-3da3-42ed-b86d-455e827c39c1" alt=""><figcaption><p>UniqueId documentation</p></figcaption></figure>
