There’s recently been a few requests, both on the forums and the discord, around dealing with object selection. More specifically, users are running into issues when they have to deal with two instances of the same object colliding.
Doing some digging into how other visual scripting systems do it (Game Maker Studio, Construct 3, etc), GD5 seems to be missing a few different type of “Pick” conditions.
Right now, the engine has the following for multi-object selection:
Looking at other engines, it really seems like GD5 is missing the following:
Pick nth object - This seems to index all objects involved in the condition, with 0 being the initial object, 1 being the next, etc. This would be exceptionally useful when checking collisions against the same object, or object group.
Pick Top Z Order - Relatively self explanatory
Pick Bottom Z Order - Relatively self explanatory
Pick Z order (with =></ equations and expressions for values) - Relatively self explanatory.
Honestly, even just “Pick nth object” would help solve a lot of complexities users are facing with object selection when dealing with groups/same objects, but all of the listed options above would be helpful.
Sadly, this isn’t really something I can implement myself as it seems like it’ll need the engine to check the backend UIDs of each instance, but I wanted to go ahead and voice the request.
Thanks all for your time at least reading this far.
Pick nth, or at least a Pick This and Pick That.
Object.This() is in collision with Object.That / Delete Object.This.
Just adding this in case it would be much easier to implement than nth Object.
Two choices would still be helpful.
users are running into issues when they have to deal with two instances of the same object colliding.
I have this with loose scenery pieces colliding with and damaging each other, I use two identical groups, “Scenery” and “Scenery_Passive”.
When Scenery is colliding with Scenery_Passive, Scenery_Passive gets damaged.
I’m looking at it again now and I’m sure I could improve the events, but at least approximately it works because I see scenery pieces getting damaged and destroyed after colliding with other scenery pieces.
Edit: I did improve the events, and now it works even better.
Agree that all of that would be useful. I do not want to introduce pick the “highest/lowest” value for variables, position, etc… because this will create an explosion in the number of actions/conditions. But for Z order, it’s true that it’s fairly common to get the highest/lowest one. A bit less sure about the last one though.
The thing is that I’m not entirely sure we can guarantee the order of objects. This means that from one game to the other, or one version of GDevelop to the other, the “first” object would not be the same.
Also not sure this is the best solution to the problem, the problem being: “How to differentiate MyObject when I write MyObject is in collision with MyObject”.
So if we go back to the problem:
Can we explain more what are the issues? If two objects collide, what do you want to do exactly? You could use sub events to differentiate them according to somethings (like were they moving or not, to add some damages of things like that).
What you can’t get currently is the “pairs” of colliding instances (which object instance was colliding with which one), but this is 1) the same if you enter two different objects and 2) would not be solved by a Pick nth?
It’s not obvious but indeed when you “pick all objects”, you basically start again and the initial state, which is: “Consider all the objects, then maybe the next conditions will refine the picked objects”.
So, I’m not 100% sure on this, but my minimap example works by checking collisions on a set of created objects, and those objects always end up with the same object # in the debugger every time it is launched. I’m not sure this is pure luck or if objects are always going to test in the same order, or what.
So this presents itself in numerous different ways, but I THINK it is always collision focused. Here’s a few examples I remember from the discord:
You are making a tetris-like game/block like game. All of your different piece objects are in a “tetromino” group. You want to set up an event that is “Separate objects” between two different members of the group, and only want to force the one that is already moving to be separated. In other engines, the one that is moving is the one treated as “initiating” the collision, so it is the first in the object list. You’d pick the “first” object and move only that one away, or if you wanted to move the “stationary” object you’d pick the second/third/last/etc object. Even with object IDs today, you cannot effectively target the different objects.
Similar to the above, you’re making a jigsaw puzzle game. All of your events require the puzzle pieces to be in a group, but when you drop a puzzle piece you want the piece dropped to be moved/snapped to the correct position (separated from the existing jigsaw piece) and the stationary piece to remain stationary.
I found that a lot of engines have this same type of issue, but have this pick nth behavior as a way to solve it. I feel like it could be important to clear up the above type of confusion:
With all of the above in mind, I do also think there are benefits of something that says “Pick Nth object” as a condition in general, even ignoring just collisions, as it would let you pick whatever order of object meets the conditions in the same box. I would think this would just work based off whatever order they show up as in the debugger, since that does truly seem static for me:
With the Multiplayer Platformer with gamepads example, the first coin on the lower left is always#40 for me, no matter how many times I restart, or even if I create a whole new example project.