How do I avoid Duplicate UIDs

Get help using Construct 2

Post » Sat Sep 17, 2016 7:19 pm

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.
B
9
S
1
Posts: 9
Reputation: 497

Post » Sat Sep 17, 2016 7:42 pm

@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.
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
65
S
21
G
90
Posts: 1,124
Reputation: 59,862

Post » Sat Sep 17, 2016 8:16 pm

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.

Image

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

Image

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.
B
9
S
1
Posts: 9
Reputation: 497

Post » Sat Sep 17, 2016 9:07 pm

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.
B
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Sat Sep 17, 2016 9:45 pm

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.
B
9
S
1
Posts: 9
Reputation: 497

Post » Sat Sep 17, 2016 10:11 pm

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.
B
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Sun Sep 18, 2016 1:33 am

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.
B
9
S
1
Posts: 9
Reputation: 497

Post » Sun Sep 18, 2016 7:20 pm

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.
B
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Sun Sep 18, 2016 10:07 pm

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.
B
9
S
1
Posts: 9
Reputation: 497

Post » Mon Sep 19, 2016 10:34 am

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).
Scirra Founder
B
399
S
236
G
89
Posts: 24,530
Reputation: 195,402

Next

Return to How do I....?

Who is online

Users browsing this forum: jezjones24, Lancifer, Magistross and 18 guests