How do I pin an object to a specific UID?

0 favourites
  • 3 posts
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • Hello Construct forums,

    I have been making a game in which enemies carry weapons, and I have stumbled across a bit of an issue.

    I have tried making code which spawns in a weapon for each enemy, assigns the object a variable which contains the UID of the enemy, and then locates and pins the object to said UID, but it doesn't seem to work.

    Any help would be appreciated.

    Tagged:

  • The two actions from the second event should just go in the first event, you are already picking the enemy for where it should set position. In fact you used spawn which means it is already at the correct position.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • lionz is right

    However, there are cases where you might want to do it the way you're doing it

    The reason it's not working is because the "On Created" is triggering as soon as the Pistol is spawned, but before the pistol has been assigned an ID

    the "On Created" trigger will activate as soon as an object is created, run the actions in this event, and then Construct will go back to where it left off

    This isn't the case inside Functions. Inside functions, outside triggers will only be activated after the entire function has run. So you could put the pistol spawning and ID setting behavior inside a function, and it should work

    The other way to deal with this is to put a "wait 0 seconds" as the first action in the second group of events. "Wait 0 seconds" waits until the next tick. So The pistol will be created, the "On Created" trigger will be activated, but then it will wait for 1 full tick before running the pin action, which will give the first group of events time to set the ID

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