How do I avoid Duplicate UIDs

0 favourites
  • 13 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
  • I'm having an issue with multiple sprites having the same UID causing issues.

    So I have a game I'm working on where there's a scanner, and I have sprites show up as "blips" on a scanner that the player can interact with. When the interaction is done, the blip is destroyed.

    I'm having duplicate blips pop up for some reason. When I destroy the blip, it's only destroying one and leaving the other with the same UID around. In the debugger all that's there for the existing one are the "Destroy" and "Highlight" options. No stats or UIDs or anything. The player can still interact with this blip infinitely which kind of break things.

    Trying to destroy the blip a second time doesn't work. If I destroy "all" blips it gets picked up and destroyed. If I save and load again, there will only be one object with that UID and it gets destroyed properly.

    Has this ever happened to anyone else? Is there any way it can be avoided?

    Edit: I'd post a capx, but I can't seem to recreate it outside of the main game I'm working on, which is pretty massive and kind of a mess.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • FaeDine - UID's normally don't duplicate, when the object is destroyed it's UID isn't reused.

    Maybe you used IID which is reused when an object that used it is destroyed.

  • Nah, definitely not the IID. When I look at the objects in the debugger, there are two distinct objects that are both identical. Same IID, same UID, same everything.

    When I destroy the object, one of them disappears, and the other duplicate shows nothing in the debugger.

    When I export a save and take a look at the JSON, I see two objects there with the same UID. I have no idea how it would even happen as, yeah, I thought UIDs were completely unique.

  • That should never happen. It's a bug if it happens with vanilla c2 features. Are you using any third party plugins, and if so which ones?

    Edit:

    Not that there have been any plugins that cause this that I know of. The idea is to isolate what is causing the issue. If it is happening reliably then you can make a copy of your capx and start removing stuff till you have a minimal capx that still causes it.

  • I've got two third party plugins (CSS Import and SpriteFont+). I really doubt either of them would be the issue, though.

    The bigger problem is that I've never actually been able to duplicate it. Multiple players have come across the issue and submitted save files (JSON strings) which I've been using to test out the bug. The bug seems to occur incredibly infrequently.

    I'm still working on figuring it out, though most of my current ideas for it are kind of off the wall, like forcing a save/load (ick), or storing all the blips in an array and recreating them regularly. I'm not a fan of either so far.

  • Interesting. Well I'm pretty sure the assignment of uids is done in only one spot in the runtime and that's when an object is created. Other than that the uid isn't modified anywhere except maybe the save/load code.

    If I'm bored over the weekend I might poke around the js files and see what there's to see.

  • If I were to take a guess at the cause, it actually seems more like an issue with an identical object being created twice than two separate objects being assigned the same UID.

  • Well I was bored and had a quick look through C2's js files. Creating and destroying seems straightforward but it gets more complex dealing with global objects and global layers.

    Are you using any global layers? my best guess is the issue may be with that somehow in conjunction with saving/loading. I'm just speculating though based on what you've said.

    Being that it isn't reproducible it's not really something that can be reported to the bugs forum. Still I'll tag Ashley to at the very least get the issue at the back of his mind.

  • Thanks for looking into it. Fortunately none of the objects or layers I'm using are global.

    Reporting it as a bug was my initial reaction, but when I looked at the (of course, reasonable) requirements, I realized it'd just be a waste of time. I've still been trying to find the cause of it. At this point though I'd really be happy to find a way to differentiate the two identical objects so I could just destroy one of them (or both) if the bug comes up.

  • UIDs should *never* be duplicated under any circumstances (they stand for unique IDs - obviously they should be unique). Any duplicated UIDs is certainly a bug, so you should report it. However it could just be a UI issue with the debugger (it may be that there really are no duplicated UIDs and the debugger is just being misleading).

  • There's definitely duplicate UIDs showing up. When I go through the save file I'm testing with I can find two instances of the object with that UID. I don't know how or when the duplication is happening though, as it's just save files submitted by users.

    Here's what's in the JSON (linebreaks added for readability):

    Here's the full JSON if it helps: https://gist.github.com/FaeDine/438e46b ... 6ae0be4a2d

    The objects are at lines 7298 and 7394.

    The object does exist twice as far as the engine is concerned. They both appear to be identical with the exception of the the "zi" data (their Z index/order?).

    I'm grabbing it by using the Browser object and using "Invoke Download of String" to grab SaveStateJSON with the MIME type of application/JSON. I have no idea if the duplicate is created during this process or somewhere earlier on.

    Ashley I can certainly submit what I have, or create something a similar project that loads two identical objects to include in a bug report. I don't know if that would actually help find cause of the issue though.

  • It's going to be virtually impossible to do anything to investigate unless you can create a minimal .capx which reproduces the problem.

  • Yeah, that's what I figured, which is why I didn't submit a bug report. It's not actually something I can duplicate. If I can, I'll certainly be back.

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