How to identify unique/specific instance of an object [sprite]

Hello everyone,

This is week 1 of my transfer from Scirra Construct to Gdevelop, and I love Gdevelop it is great. I am not going back to Construct, and will be using Gdevelop from now on.

I have a question I cannot find an answer anywhere:
In Construct each sprite has a Unique ID (UID). For example, if you create 10 identical coins on the screen, each coin will have a unique IUD number. The system auto-creates this for you, when the game runs and is a read-only number. So during collision detection, you can have a way identifying which coin was hit [let’s say you need to know which specific coin it was].

Does Gdevelop have UIDs or something similar to it?

Any help you can provided is greatly appreciated, and thank you in advance for your time and your help.

Hi, there is an extension that probably does what you want:

Hello, The easiest way is to place a variable named ID (for example) on each object. Then you have to manually give a different number to each object. In the code you have to add to the search condition the condition variable object ID = X. Hopefully this will meet the expectation.

APardaillan is right but you don’t even need to do this manually, you can do this in the events as shown below:

Hello! Note that while GDevelop may look and feel similar to construct due to similar approaches at visual scripting, they are very different engines and concepts from one may not apply to the other.

GDevelop doesn’t give IDs to objects because those are considered an anti-pattern by the maintainer, everything you can do with those you can do more cleanly another way.

In GDevelop, we use object selection: conditions that use an object are executed for each object instance, and further conditions and actions that use the same object will only use the instances for which the condition was true.

If you need to remember some specific objects for later, you can mark the instances with an object variable, and use them later by adding a condition that checks if that variable was set to your value.

Similarly, if you need to apply an action on one specific instance that you prepared on the scene, you can modify the instance variables of instances on the scene, and set one to for example the boolean true to make it targetable by your events.

Generally, it is not recommended to try and make UIDs for GDevelop objects. While it is possible with a for each object loop at the beginning of the scene, it is not the GDevelop way and won’t work as well, since GDevelop is not made or optimized for that.

Thank you everyone for the wonderful and detailed reply back to me. I appreciate you all for giving me feedback on: available extensions for UUID, ways of adding a variable and 2 different ways setting its values, and about the Gdevelop best-practices of what is recommended to do and not to do.

I will review each alternative, play around with them in test projects and go with the one that best fits my particular fact pattern.

Again, thank you all for your help. I realize Gdevelop and Construct are different, and that difference is preciously why I fell in love with Gdevelop and will stay with this engine.