Download

Making events work with more than one of the same Blueprint Simultaneously (Blueprints)

Hi guys,
This is my first time on the forums.
I have created logic where the player can fire a special projectile at the enemy Blueprint which then allows you to dash towards the enemy target. The Blueprint works wonders. however I am having issues when it comes to making it work on more than one of the same enemy (all of the enemies are the same Blueprint that have been dragged on to the map). it seems the mechanic will work on the first enemy, then once he has been destroyed it will then work on a new enemy, therefore the logic does not work at the same time. I noticed this to only be the case for my dash event.

I read somewhere that for supposed to use a for loop to make it read from every instance, however I could be completely mistaken.

If anyone knows how it could be fixed or what I’m doing wrong please let me know. I’m still fairly new to Blueprints.
Thanks in advance. :slight_smile:

I think your problem lies in the enemy variable or rather that you overwrite it with the “ForEachLoop”. It will basicly get all your actors, pass the array into the “ForEachLoop” and overwrite the “Enemy” variable with new enemy entries. So in order to do that properly, you should remove the “Set Enemy” node and instead put in the “Grapple Light Change” after the “ForEachLoop” and replace the “Grapple Light Change” with your call of the “ActorsOfEnemy” event.

I made a dummy blueprint actor to resemble your setup. I made modifications and I think it should look like this:

Hey DarkGodsLair,

I tried what you gave to me and i still couldn’t get it to work. It seems to work fine until there’s more that one. it’s almost as if the only allows it to happen to one blueprint first and only then it can do it on the other Blueprint.
This is a visual representation of what I mean.

https://youtu.be/XhkNn8GDPrk

Thank you for helping!

You seem to have a fairly bad understanding of object oriented programming, so let me try to break down what’s wrong with it:
When you call your dash event, the dash is executed exactly once for whatever enemy that is in your enemy variable. That you cycle through all enemies in a for-loop doesn’t do anything besides saving the last found enemy in your enemy variable.
You would need to call the dash event multiple times for each enemy, where your enemy variable is always the next enemy to dash to.

So you would need to call your dash event once in succession for every enemy you want to reach. I guess you want to dash at them one at a time? So from your location to enemy 1, then enemy 2, then enemy 3 and so on? Then you also need to wait to reach your target before setting off the next impulse. You could add an enemy input to your event and then call your dash event with the enemy in your for-loop.
However, be aware that for-loops and delays don’t like each other… they basically don’t work together, so you should expect to have all of your events to go off almost simultaneously. There is a way to change how the for-loops work by writing your own. You can set a delay there.
Check out this article:
http://iryos-workshop.com/en/forloop-withdelay-ue4/

Sorry, yes I am very new to programming.
Yeah the idea was to dash to them one after another. I’ll do what you have said and tell you how I get along. Also that you very much for the article! it will be of great help I’m sure.
Thank you for helping!
I’ll keep you notified on how I get on.

Hi again Quexlaw
I did some fiddling and I’ve managed to get it to work when I made a custom event inside the enemy Blueprint which is a just calling my dash event from my player character Blueprint.

Was this what you were meaning? This works perfectly now and is working for each enemy no matter what order they’re in. However, the problem it the action is automatic and before i had it so press CTRL a second time to actually dash. I guess this can be easily changed? Maybe with a branch and a Boolean or something like that?
I also got rid of that forloop inside the Get All Actors of Class event.
Thanks again for helping me!

No worries, while I have a few years worth of programming experience I’m still far from being a pro lol

You have to understand that no matter where you put your code, it just does what is written there, once.
In your case, you seem to use an overlap event with a collision capsule, then use your DashFromPlayer event to trigger your dash.
This is automatic because the overlap event is the one thing that triggers this chain of code.

The way I do my code is that I ask myself what I am actually doing. Most of my coding errors come from me thinking that I’m doing something that I’m actually not doing. In your case, just ask yourself what actually happens with your overlap and your projectile. If you call your dash event when an overlap happens: of course it will get triggered once the overlap happens.

Ask yourself what it is you want to do: you want to shoot multiple enemies, then dash to them one after another once you give the command. That means that something like an overlap event is not allowed to trigger your dash, because you have no control over it anymore. Rather, you want to shoot them first and then you want to check which enemies you have actually hit. Maybe there are three enemies but you have only hit two of them? That means you need some kind of status to check whether they are eligible to dash to them or not. Since it’s two choices, use a boolean.

Then, you want this to be triggered only when you give your input, meaning, everything starts once you press something. That means your first step in using your multiple dashes is an input. You can define it yourself in your character or character controller blueprint. Then, after you pressed your key, you want to look at which enemies you want to dash to. Only those eligible, meaning those that have their boolean value set to true (those that have been hit by your projectile). Then you have to go through all of the eligible enemies one after another. You basically have to do what you want to do with a single enemy with all of them. However, the delay problematic comes into play, so you need some kind of fix for this. The for-loop with delay works, but it’s a constant value, which is not ideal. This means that no matter whether you actually reach your target or not, no matter the distance, the next impulse comes. That is something you have to tweak for it to be really good.

But anyway, since your problem is a little more basic, I made a small example that should show you how it should work in general:
fa3278117cf4fe46d6edd9ab238fcf9f938fccd5.png

This is in the character blueprint. So, what happens is the following: once you press left CTRL, the engine retrieves all actors of type Enemy. Then, each one of those is sampled: is his boolean value true? If so, use the dash event and give this event the Enemy to dash to as parameter, so we can calculate the direction we want to go. The way you calculate this direction is always the same for each enemy, so we don’t care about the actual values; that’s why it’s okay to use each individual enemy one after another. After the dash is over, we return to where we were before and end up in a Delay of 0.2 seconds. This doesn’t work because of the for-loop, but you should get the point and be able to implement a for-loop with a working delay based on the article I’ve sent you.

Keep in mind this is a brute force approach, as we get each and every single enemy in existence, which is quite costly for performance (it doesn’t matter for your game, but it’s something you should keep in mind). It would be better to add or remove the eligible enemies to an array of sorts, so you only have to go through a much smaller subset of enemies. Also, there currently is no order to the multiple dashes. Currently, you would simply dash to the enemy in the order the engine checks them in. It would be better to sort the array first based on, for example, distance to the player, so that you always dash to the nearest eligible one. You can add inputs to events by pressing left click on it, then adding them in the details tab.

Ah this is fantastic! Thank you very much.
That’s a good methodology to go by that will help me a lot when I’m working with Blueprints. I’ll definitely go with using a Boolean.
I am going to look into this this is amazing I didn’t even know you can add inputs and things like that.

Again thank you very much! :slight_smile: