# Evenly distribute/split homing projectiles between multiple enemies

**URL:** <https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [September 4, 2023, 3:01pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837 "2023-09-04T15:01:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 4, 2023, 3:01pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/1 "2023-09-04T15:01:11Z")

</div>

Hello,

I am working on a character or some type or turret if you want, that shoots six homing projectile instances at enemies in a given range. The homing logic is made with the “Set Homing Target Component” node. Now I want all six of them to evenly split between enemies. So if there is only one enemy, he gets hit by all projectiles. If there are two, each gets three projectiles and so forth. For the uneven numbers, the spare projectiles need to be distributed to the closest enemy or enemies. That is probably done with some kind of “Get Distance To Actor” logic or something, but that is not the important thing right now- The part I stuggle with is the distribution. Everything esle is working so far.

So if anyone has an idea how to implement this, I’d be happy to read your answer!

Edit: Some additional information in how I try to make it work:

|-|If there are no enemies in the detection radius, the ability cannot be activated|  
|-|If there is one enemy in the detection radius, it gets hit by all six projectiles|  
|-|If there are two enemies in the detection radius, they each get hit by three projectiles|  
|-|If there are three enemies in the detection radius, they each get hit by two projectiles|  
|-|If there are four enemies in the detection radius, they each get hit by one projectile and the two enemies closest to the player character get hit by the fifth and sixth projectile respectively, all enemies get hit at least once, two enemies get hit twice|  
|-|If there are five enemies in the detection radius, they each get hit by one projectile and the enemy closest to the player character gets hit by the sixth projectile|  
|-|If there are six enemies in the detection radius, every enemy gets hit by one projectile|  
|-|If there are more than six enemies in the detection radius, the six enemies closest to the player character each get hit by one projectile|

Here is how I set it up, which could be an entirely wrong approach, typical beginner mistakes:

I have the character BP for the turret. There is a sphere collision that constantly checks, if an enemy is within the sphere. If so, I can press a button (for testing purposes) to put all detected enemies in an array (not yet based on distance, I am just using six dummies for now) and then spawn a projectile BP six times (so six instances) and call an event in the projectile BP, so they would set their homing target when they spawn.

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [September 4, 2023, 4:08pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/2 "2023-09-04T16:08:00Z")

</div>

First you need to get all enemy actors, and sort them by distance.

Old topic about it (i recommend C++ code):

> [@How do I sort an array by distance?](https://forums.unrealengine.com/t/how-do-i-sort-an-array-by-distance/410764):
>
> Hello, I’m creating a third person shooter game and I want my companions to follow me in a V Formation. I have gotten the formation already but the function that I used to sort the companion array by distance is not working well. Because the formation is symmetrical, when the player continues to move in the same direction, the two companions beside it maintain the same distance from it, hence the function tends to resort the array and make the two companions swap sides. I have tried sorting the…

when you have that sorted by distance array. Shoot those projectiles in order.  
When there are left, go for second loop.

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 4, 2023, 7:29pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/3 "2023-09-04T19:29:26Z")

</div>

Well that would take care of the distance problem. So thanks for that! Now what’s left is the even distribution part I guess.

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [September 4, 2023, 8:57pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/4 "2023-09-04T20:57:11Z")

</div>

Sorted by distance array solves distribution, for any number of projectiles you want shoot and any number of targets. So you can have multiple turrets shooting multiple targets. However that would need some more thinking about how to make distance function.

Let me explain (assuming single turret, that shoots 6 projectiles).

- first it sorts enemy targets by distance.
- so if there is more targets than projectiles, it will shoot 6 closest targets.
- if there are more projectiles than targets, it will shoot all targets at first,
- then remaining projectiles will be shot at closest targets.
- and loop trough targets until all projectiles are fired.

So if there are 6 projectiles and single target, it will loop 6 times each time shooting at that single target.

For two targets it will loop 3 times, shooting at closest then other one, then repeating

For 4 targets and 6 projectiles, it will shoot all 4 of them, then loop it and with 2 remaining projectiles it will shoot second time at two closest targets.

So just make sorting by distance array. I suggest map variable that as index has distance (rounded to closest int), and as variable, it has either target location or target actor reference.

_Uh, forget MAP variable, you cannot have 2 entries with same key._

So only way is to make struct then sort array of it by float as key.

PS. just found some great source for sorting in blueprints:

> [@Sorting algorithms in Blueprints](https://forums.unrealengine.com/t/sorting-algorithms-in-blueprints/1135992):
>
> It is common knowledge that blueprints do not include sorting functions. In my previous experiences, I have been able to create simple sorting functions easily. However, during my current project, I faced the challenge of sorting large data arrays and found that the sorting process was either very slow or unsuccessful. Since I wanted to avoid using C++ code or third-party development, I independently researched this issue. After conducting some research, I have decided to share my findings in t…

pps. However i think C++ would be much better for this.

and that sorting topic has link to FREE functions made in blueprints, that has SORTING:

> **[LE Extended Standard Library in Code Plugins - UE Marketplace](https://www.unrealengine.com/marketplace/en-US/product/low-entry-extended-standard-library?sessionInvalidated=true)**
>
> This plugin provides you with blueprints that add general functionality and improvements.

So get that, use it to sort targets.

---

<div class="post-metadata">

**Author:** ![gardian206](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gardian206](https://forums.unrealengine.com/u/gardian206)\
**Post date:** [September 4, 2023, 9:29pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/5 "2023-09-04T21:29:22Z")

</div>

depending on how often you are doing this C++ might not be that much of an improvement, and it can be speed up considerably still by using “Get Squared Distance” (just keep in mind the distance limit would need to be squared to compensate) this way so save having to do the most expensive part of distance checks being the square roots.

once the array is sorted (or even during the sort) anything outside the range would be removed. the reason to suggest C++ for array sorting is to define a sorting predicate, but by nature of sorting predicates they can not trim/remove. and trimming would make sorting faster, but we come back to how often this is going to be happening.

if you don’t want to go into C++ just don’t have this be usable too often. get all Actors of Type then walk through the array doing a distance check if greater then distanceMax remove them.

then you would sort the Array (this is where C++ you could define a sorting predicate, but) this is doable in Blueprints as long as you don’t do this “to often” you can look here for implementing a sort [How to sort an array?](https://forums.unrealengine.com/t/how-to-sort-an-array/464874) in blueprints.

for the distribution system given your criteria, have a temp integer equal to you ProjectilesMax, then there are a couple of options depending on code flow if `if(Array.Length >= ProjectilesMax)` then just use a loop  
`if(Array.Length < ProjectilesMax)` then you need a bit more

 ![MaxLoop](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/5/5/45580d33ef41a9c8758c1e49994a5edd1057b34c.png)

the getting the array could be cleaned up by using a manager to keep track of your Entities, and you could cash the distances on the first traversal to save on math for each compare, but these are optimizations.

other optimizations after it is functional:

- object pooling so you don’t have to create and destroy these objects all the time which can lead to segmentation
- replace the top for loop with maybe a `Do N` where the target index would also be the CurrentN (only do this if the Length is less then the MaxProjectiles) this might require unit testing to determine if it is faster.
- do these need to be physical objects or could they be just a visual effect after a trace

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [September 4, 2023, 11:06pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/6 "2023-09-04T23:06:19Z")

</div>

iterating through the array takes care of that naturally:

1 for you, 1 for you, 1 for you…

still three missiles to go, but no more bad guys? Back to the start → 1 for you, 1 for you.

(didnt realize there was more answers above before posting this)

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 5, 2023, 1:38pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/7 "2023-09-05T13:38:15Z")

</div>

Okay, I tried to implement what you wrote and made in the screenshot, buuuut didn’t work at first. So maybe some more information how I initially set it up. I must mention I am trying to learn programming at the moment, so I am not yet familiar with many things, so an explanation for dummies here and there is much appreciated! Knowing what is supposed to happen in your example is (for me at least) a big help to learn and understand these things.

I have the character BP for the turret. There is a sphere collision that constantly checks, if an enemy is within the sphere. If so, I can press a button (for testing purposes) to put all detected enemies in an array (not yet based on distance, I am just using six dummies for now) and then spawn a projectile BP six times (so six instances) and call an event in the projectile BP, so they would set their homing target when they spawn.

Maybe that is the wrong approach, I don’t know. It has always and only worked for one enemy so far.

Now I am not sure where I would put what you made in that screenshot and if I need to change something in my setup.

But I am still glad for your help so far! That goes for everyone here of course.

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 5, 2023, 2:18pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/8 "2023-09-05T14:18:44Z")

</div>

That’s what I thought, too. But every instance seems to be focused on a specific target. Who knows, maybe I messed something up, I AM a beginner at the end of the day.

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [September 5, 2023, 3:07pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/9 "2023-09-05T15:07:22Z")

</div>

you’ll probably have an easier time if you first get just each small part working in isolation, away from your main project. Learning to work with arrays is important but it is confusing at first, so it’s a lot easier to do some simplified testing first.

You might setup an array that just prints strings and runs from button press in a separate project in order to figure out the iteration part. This way you don’t have any additional hijinks with the referencing different actors and so on.

---

<div class="post-metadata">

**Author:** ![gardian206](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gardian206](https://forums.unrealengine.com/u/gardian206)\
**Post date:** [September 5, 2023, 5:16pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/10 "2023-09-05T17:16:20Z")

</div>

“a sphere collision that constantly checks”  
this could be somewhere between Ok too, PLEASE don’t do this collisions can be rather intensive. if you want to check spherical collision with regularity then you could have the Sphere Collider set to `Generate Overlap Events` (it is under Collision in the details window for the collider in question) then place its `OnBeginOverlap()` (you can right click the collider in the Hierarchy-\>Add Event-\>OnBeginOverlap), and its `OnEndOverlap()` (same process just pick OnEndOverlap). in the `OnBeginOverlap()` check for the relevant things that define a target, and add them to an array. in the `OnEndOverlap()` remove the target from the array (it is safe to remove something from an array that was never in the array)

the other method would be to every so often do a `Sphere Trace Multi` every so often this way you can specify your criteria at the point of the Trace, and you will get an array anyways. you can even have the start point and end point be the same for just a “within this radius”

once you have the array and it “canFire” then sort the array for your criteria (keep in mind that a sphere radius followed by a distance sort will return things even if it is behind, above, or below the checks source this would require an extra angle check to determine if it “is in front of”)

the image I posted would be at the point of firing, and I even included a function call to “FireProjectile()” (this will probably need to be an event as things like spawning actors need to be in Events as the engine will prefer to spawn Actors Asynchronously to prevent stutters but when you have object pooling it could be a function as you would just be placing the projectile at its starting point, orienting it, and then activating it)

- first we check to see if the `Length()` of the Array is `Greater then or Equal to` the Max projectiles. True go to point 2, False GoTo point 5
- we start a for loop Iterating (walking/traversing) through the array
- on each of those Entities we call `FireProjectile()` with the Entity as the target
- then we check to see if the index of Entities is greater then MaxProjectiles (looking at this again it is actually wrong, and should be `MaxProjectiles - 2` as projectile 1 will be shot at index 0, Projectile 2 will be shot at index 1, … projectile 6 will be shot at index 5, but I am breaking at the end meaning I need a `minus 2` if I put the check at the start it could be `minus 1`) if the test is “true” then we break out of the loop early
- I set `RemainingProjectiles` equal to `MaxProjectiles`
- start a while loop that will continue as long as `RemainingProjectiles` is greater then 0
- inside the While Loop I start a For loop iterating over the array
- calling `FireProjectile()` on the element
- decrement `RemainingProjectiles` (this is the same as `GetRemainingProjectiles()` → `RemainProjectiles-1` → `SetRemainingProjectiles()` compressed into 1 node)
- check to see if the amount of RemainingProjectiles is still Greater then 0 (which upon inspection should probably be a “`less then or equal to`” node instead as the current check is the opposite of what is needed)

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 5, 2023, 5:16pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/11 "2023-09-05T17:16:25Z")

</div>

Absolutely. I’ve worked with the Print String quite a lot, but am not always realising what might be wrong. But in regards to what you said at first with iterating through the array. Maybe you can spot a mistake in my setup:

So when enemies are detected, the turret can shoot on a button press for now, like the 1 key. That also adds all detected enemies to an array. Then the projectiles get spawned, six instances to be exact. When they spawn they iterate through the array of detected enemies with a “For Each Loop” node and whatever comes out of there is the selected target.

I am pretty sure something is wrong about that approach, but I can’t put my finger on it ☹ Maybe it’s because of the instancing of the projectiles.

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [September 5, 2023, 5:48pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/12 "2023-09-05T17:48:59Z")

</div>

share your blueprint code, will be easier to see.

also you’’ need to for each from the bullets probably, because you are doing something per bullet.

so for each bullet, you’ll be going ot the next enemy in the enemy array, and when you reach the end of hte enemy array, then you start back from beginning of it (if there is still bullets left)

this will be pretty tricky if you are getting used to blueprint arrays, but easier to see what you are doing with some images.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [September 5, 2023, 5:54pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/13 "2023-09-05T17:54:16Z")

</div>

Hey @MatzeOoo

Made a simple project to try and (hopefully) illustrate what has been shared above.

![Turret](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/6/9267b3ce2fb18306524c64a6d0f963818ded4968.gif)

[TurretTest\_UE5\_2.zip](https://forums.unrealengine.com/uploads/short-url/p2UNyjsoY387sJMu3F8C1I7pyc6.zip) (75.9 KB)

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 6, 2023, 2:16pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/14 "2023-09-06T14:16:46Z")

</div>

Holy smokes, thanks for the effort! I tried to set it up as you did and in theory it works! Everyone gets registered and those too far away got sorted out. Buuuuuut for whatever reason they still like to chase one and the same target.

I created your logic, functions and all inside the projectile blueprint.

 ![Screenshot 2023-09-06 155709](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/f/84feaf8a1d150789670b5bd889794c8e8abcd9e6.jpeg)

Not tidy, I know. But maybe it doesn’t work because each projectile instance runs through that individually? So what I think, and correct me if I am wrong please, is that some of the parameters need to be set in the character/turret blueprint or set globally?

What I also tried was to create the logic in the character/turret blueprint and assign the homing target via a custom event after a projectile is spawned, but that didn’t work at all.

But at least it looks like this now:  
 ![ezgif.com-video-to-gif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/5/8650c007fbc0e7c628592ce9b8b6fafaefd50b21.gif)

Yeah, I used a Third Person Character as turret 😃 Please ignore that.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [September 6, 2023, 2:25pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/15 "2023-09-06T14:25:15Z")

</div>

> [@MatzeOoo](#):
>
> to create the logic in the character/turret blueprint and assign the homing target via a custom event after a projectile is spawned, but that didn’t work at all.

This.

Assign the target as they are spawned. Notice the end result was an array of actors and an array of integers; the int array has distributed the amount to spawn and the reference array the target that correspon to each amount.

This should be in the class that spawns. The only job for the projectile is to navitage to the target.

* * *

Idealy you can save yourself the int array and spawn them in that loop. It was done mainly for debug… but it works either way. There are also better sorting algorithms you can go for, @Nawrot shared a priceless link for that. From that link check out shell sort.

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 7, 2023, 1:57pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/16 "2023-09-07T13:57:49Z")

</div>

Hey, I tried it again to do that in the character/turret blueprint and now it actually WORKS! Except for the part where the projectiles now spawn from only one socket but that is something I can hopefully do on my own.

I will also look into what the others said regarding using a sphere trace and such.

Big thanks to everyone who helped me! @pezzott1 @BIGTIMEMASTER @gardian206

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 9, 2023, 3:05pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/17 "2023-09-09T15:05:47Z")

</div>

Hello,

sorry to bother but it looks like I need help again. I fiddled around to try and fix this but I got the issue that even though I want to spawn only six projectiles, I spawn projectiles per socket based on number of detected enemies. I certainly know why thanks to the For Each Loop node, but I can’t find a way around it.

To summarise: I want to spawn one projectile per socket (there are six sockets, makes six projectiles max.) but instead I spawn as many projectiles per socket as amount of enemies detected

 ![Screenshot 2023-09-09 165946](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/4/3/c4337216432699774e816933919f98030bb1e999.png)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [September 9, 2023, 4:04pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/18 "2023-09-09T16:04:14Z")

</div>

IMO this is how it could work:  
[TurretTest.zip](https://forums.unrealengine.com/uploads/short-url/h8vQR2yQzbXMJ7rvHbs2ADABdwj.zip) (90.2 KB)

For example:

- 6 distributed on 2 targets.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/f/02fbee4a6c8583d8525054d79e29c85dbb12deb2.jpeg)
- 6 distributed on 4 targets.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/7/5f75c8e0c32e0e9bfa6f25b01c01df1135ef9fb2.jpeg)

---

<div class="post-metadata">

**Author:** ![MatzeOoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MatzeOoo](https://forums.unrealengine.com/u/MatzeOoo)\
**Post date:** [September 11, 2023, 10:10am UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/19 "2023-09-11T10:10:01Z")

</div>

Okay, so I tried to use my homing logic in your example here in case I did something wrong in my project, buuut in both cases it only worked in theory, by that I mean with the traces. In case of two enemies, still only two projectiles spawn.

I still think there is something wrong with how I set it up. I mean if it only finds two enemies it will based on what I built only spawn as many projectiles, up to 6, but I can’t think of another way to determine the targets. ☹

But see for yourself:

[TurretTest.zip](https://forums.unrealengine.com/uploads/short-url/iXgw02mW5K3OwZkIKEVwq411Uy.zip) (1.7 MB)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [September 11, 2023, 1:29pm UTC](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837/20 "2023-09-11T13:29:08Z")

</div>

I suggest you try and recreate it to understand how it works. Feel free to ask if you ever get stuck.

![Turret](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/1/4/5142bc1341dd63b9e08f6dd073b6d521ac455039.gif)

[TurretTest\_UE5\_2.zip](https://forums.unrealengine.com/uploads/short-url/wikkEuxut9gO80QU8GGlVShggqk.zip) (109.6 KB)

[Next page](https://forums.unrealengine.com/t/evenly-distribute-split-homing-projectiles-between-multiple-enemies/1282837.md?page=2)
