Custom Targetting system won't work

hi, I am new to GDevelop. I am trying to make a custom targetting system for my AI which uses team stats, but it does not work.

I tried debugging it, and have found that it works when only the player is in the targetables group.

in another test, I added a variable which resets every loop, and adds by one for every found targetable, and it was stuck at one, so I either messed up the variable setters, or it is only selecting one target, and then ending.

also this is an external event which the main scene calls.

here is my code:

any help would be appreciated.

I’m assuming what you’re trying to do is find the team’s targetable object that’s closest for each team’s pathfinder object?

If so, you could use:

1 Like

Hello, thanks for reaponding I updated my code to this:


but it still does not work.

I am sorry I typed that in a rude way and typo’d. is it possoble tp edit comments?

I can’t see what’s rude about your response. No apologies needed :smiley:

Why are you using not equal when comparing Pathfinder.Team and Targetable.Team? Shouldn’t is be equal to (‘=’)?

1 Like

no, I am trying to make it find enemies to target

So targets from another team? What does it do currently - where do the pathfinder objects move to?

yes, and currently it does not move anywhere.

Can you confirm that

  1. All the objects in the pathfinder object group have the pathfinder behaviour.
  2. None of the pathfinder objects also have the pathfinder obstacle behaviour.
  3. All PathFinder objects have a valid Team variable
  4. All Targetable objects have a valid Team bariable

If those two checks are good, then you could test each bit of the object selection and pathfinding:

  1. Add 2 temporary events - the first that sets the tint of all Targetable objects to “255;25;255”, and a second where if a pathfinder has the mouse over, than all Targetable objects with a different team id have their tint changed to “0,255,0”. This will colour the targetable objects green.
  2. If this highlights the correct Targetable objects, then add the condition to select the Targetable object nearest the PathFinder object.
  3. If that highlights the correct one, then wither remove all the pathfinding obstacles and see if the pathfinder then moves.
1 Like

I did the first two steps, and it kind of works, but the objects don’t select other instances inside of their own entity type apart from themselves. also there are no pathfinder obstacles in the game

also here is the code I’m using

So are Pathfinder objects also a member of Targetable objects?

1 Like

yes they are also a member of Targetable objects

Ah, and therein lies the problem. When you repeat over each Pathfinder object, you are only looking at the one pathfinding object at a time. Unfortunately, this also limits the Targetable objects to just that one object that the Pathfinder repeat has selected.

To get around this, create 2 variables to store the Pathfinder’s X and Y co-ordinates, and then use the condition ‘Pick all instances of Targetable’ before finding the closest Targetable object. Something like:

An explanation:

  1. The repeat event gets the x and y position of the current pathfinder object
  2. The first subevent then select the nearest Targetable object tot he x & y position from all of the Targetable objects. I’ve reused the 2 position variables as they get reset in the next repeat iteration. Note that the pick all and pick nearest are only in scope (or valid) for that event and any of it’s subevents. They are not in scope for sibling events, or events that are on the same level as this event.
  3. The last subevent uses the current Pathfinder object from the repeat and moves it. It is not affected by the previous events select all or pick closest - those conditions are only part of the previous event
1 Like