Do extension conditions perform object picking?

I have an extension condition that checks if objects are selected (by looking for a specific object variable).

I want this to only pick the objects that match the condition (like normal conditions work). However, it seems that my extension condition is always picking all instances of the object.

The code above makes ALL units move, regardless if they are selected or not.

What am I missing?

:thinking: I am not sure what might be going on here, object selection should work in that case afaik. Does using the variable condition directly pick objects correctly?

i had the same issues with picking objects in functions.
i got the impression that if you pick an object inside a function it is picked only inside the function itself, and gets unpicked right afterwards.

maybe it was just in relation to groups, not entirely sure, if it is this might be the reason.
Deserves some testing

That is true, but in that case, the custom condition is an object condition, so the code generator should automatically call it for each instance and filter out instances for which the condition is false, no matter how it is picking objects internally.

might be right, but when it doesnt remember which objects where picked (if returns true)
the return value only remembers the object, not the picked instances.

@tristanrhodes but this function in itself doesnt seem to be badly needed anyway, just using the boolean condition itself seems alright to me, or do i miss the point?

No, this is an internal variable used by the extension. Extensions should not be interacted with via variables but via actions, conditions and expressions. Not doing so doesn’t respect the best practices, which should be followed for an extension to be submitted to the gallery.

Yes, the picked instances inside of the custom condition are not remembered but that shouldn’t matter anyways, as GDevelop should execute the condition once for each object, only caring if it returns true or false and unpicking the objects that have a return value of false on that condition.

got it :+1:

this is what i dont get. The return value is not part of the object (like an object variable would be), it just uses objects as conditions. once the functions value returned and unpicks the objects, all you have left is a true/false, not any picked objects?

Yes you have only one true/false, but GDevelop will for any condition that accepts an object as parameter execute it once individually for each instance and unpick that instance if the return value is false. The condition will only trigger if at least 1 instance is still picked. That is how object selection works with all conditions in GDevelop.

but isnt the condition completed before going to the next event/subevent?

No, it doesn’t pick all objects and unpick all objects. Basically that is what any condition that accepts an object look like (no exception for custom conditions):

const pickedObjects = [];
for(const object of previouslyPickedObjects) {
  if(condition(object)) pickedObjects.push(object);
if(pickedObjects.length !== 0) {
    // next conditions, actions and subevents

The condition gets passed each instance one after the other, and if the condition returns true, GDevelop will pick it for next conditions/actions/subevents, else it is unpicked. Whatever object picking happens inside the custom condition doesn’t matter or influence the object picking outside of it.

I really appreciate you guys thinking about this. I wrote this post late last night, so I still need to take the time to create a minimally complex example to test it (hopefully tonight).

i did a super simple test:

with for each:


Seems a for Each is needed. :man_shrugging:

1 Like

That’s odd :thinking:

I can confirm my game logic worked when I put my extension condition under a ForEach() loop.

I’ll let Arthuro ponder the implications, but this is not holding me back anymore.

Thanks @Slash!

I looked at the exported code for a similar example and, indeed, GDevelop doesn’t seem to be using a “real” object parameter but an objectsLists parameter for manual picking :thinking: So the default object picking doesn’t apply to those custom conditions.

1 Like

@arthuro555 Should I make a feature request to implement object picking on extension conditions?

1 Like

Yes, definitely! It is also blocking this extension: Update: Fix a context issue on FireBullet · Issue #124 · GDevelopApp/GDevelop-extensions · GitHub

1 Like