Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving objects unique ids onStart

I have a bunch of gameObjects that I am assigning unique ids to in the Start function.

void Start() {
    UniqueID = String.Format("{0:X}", DateTime.Now.Ticks);
}

I thought this would work but every now and then I get duplicate ids. How can I make sure that they are always unique?

like image 940
Ogen Avatar asked Jun 17 '26 02:06

Ogen


1 Answers

I would use a guid.

UniqueID = Guid.NewGuid.ToString();

Using your suggestion, 2 instances running at same time, may apply the same "unique" UniqueID to 2 different objects.

Guid should be unique even across instances.

like image 112
DermFrench Avatar answered Jun 18 '26 16:06

DermFrench



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!