Home

Awesome

Unity GUID

Globally Unique Identifier

An implementation of a GUID, it can be used standalone, with the GUID component provided, or inside any script which can derive from it. Unlike Unity's Object.GetInstanceID() this implementation is persistent as it gets serialized inside the component itself.

Features

Guides


Installation

Package Manager via git URL

  1. Open Package Manager via Window > Package Manager
  2. Add package from git URL...
  3. Enter https://github.com/stonesheltergames/Unity-GUID.git <img width="500" alt="package-manager-install" src="https://user-images.githubusercontent.com/5909516/155850620-c7e7d61c-d6c2-4bf3-b84e-ba4bcd439ace.png">

Manual install

  1. Download this repository or one of the Released .unitypackages at https://github.com/stonesheltergames/Unity-GUID/releases
  2. Copy the files or extract the .unitypackage inside the root of your project (you can move the folder anywhere you need after that)

Usage (standalone)

You can add the GUID component to any gameobject by clicking Add Component > Stone Shelter > Core > GUID

Usage (script inheritance)

You can inherit from the GUID script and add your own functionalities on top, remember to include the correct namespace by adding on top of your file:
using StoneShelter;

Scripting

Inside your scripts you can retrieve the GUID from a gameobject by using GetComponent<GUID>().guid which will give you the current GUID as a string.
You can also retrieve any object from any scene with the static method GUID.Find(guid) where you can pass a guid as a string.

GUID generation and reset

When you add a GUID component (or a component derived from it) for the first time to a gameobject a new GUID is automatically generated:

You can manually generate a new GUID or reset it (for example if you duplicated the gameobject) from the context menu by clicking on the three dots on top of the component and then clicking one of the options on the bottom:

Prefab workflow

If you are working with prefabs there are some things that you need to know: