Getting object UID when clicked on.

0 favourites
  • 6 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • The title actually says it all - I need to get the UID of the object I click on. I am creating a Tower Defense game and need to apply properties to specific instances.

  • ...I need to get the UID of the object...need to apply properties to specific instances.

    In that case you need IID (Instance ID) and not UID.

    Global Var: ObjIID = 0

    On left mouse click on Object | Set ObjIID to Object.IID

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • UID works perfectly fine for identifying specific instances, and in some cases is more reliable than using IID. But the process is similar. On clicked object, set variable to object.uid.

    IID: Best when dealing with order - first, second, third, next to last, last ect...

    UID: Best when needing to reliably identify specific instance of any object.

  • After adding mouse object;

    on object clicked >> Set instance variable (value) to "object UID"

  • Solved! Thank you. I knew that I wanted the UID in the object's class, I just wasn't sure what to do in the event sheet to get it. I tried:

    Event On mouse - On turret Clicked

    Action on turret - ???

    There was no option to get the ID of the turret when you are in the action menu for the turret, one needs to just select whatever variable you want and set it's value to Turret.UID, that didn't really make intuitive sense because just turret feels like it refers to the class as a whole and not the selected instance.


    Picking - conditions pick, or "filter" instances. When your specify on object clicked, only the one that was clicked is applicable to the actions, thus allowing you to get that one UID. If you didn't narrow down to only one instance, it wouldn't work right. Therefore watch out for situations where you might click two of the same overlapping object - you would only get the UID of one of them. To fix that, you would need an additional condition to figure out which one you wanted (pick by z order to get the one on top is one solution).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)