Multiple enemy targetting system / camera lock

Hi all,

I’m making a small hack and slash game and was hoping somebody could point me in the right direction. This is the working camera lock on an emenies direction so far -

So far I have a targeting system which will target the closest enemy, this only works on one enemy type at the minute. As soon as I introduce a different enemy AI, I cannot seem to work out how to find the closest enemy out of a a selection of enemies.

First of all, I started looking into using parents on the blueprint. Unfortunately I didn’t realise I could do this at the start from a template enemy AI. (I wish I did!) Although, when I try and now reparent the all the enemy AIs together, they all get eachothers weapons, and so forth kick out quite a few errors, as they have different blueprint attacks. I thought this would be the best way to do it, only if I was creating the enemy from scratch again.

I’ve tried to add a tag to the enemy AI, which seems like a great idea. But I can’t seem to cast “Get all actors of class” more than once. As the ForEachLoop array can only have one input. So I’m only actually able to cast to one actor type, which makes the tag abit useless.

I think the best way would be to limit everything to go under one array like you suggested, so I created a “AllEnemyCombination” blueprint interface, and add the all the other blueprints into this, which seems to work. But this seems to break down as soon as I have to start calling the variables I’m using to calculate the closest distance.

I’ve attached a image of the targeting system which I’m using, also a copy of the project file if you would like to look

Hi Folks,

Just a little update, if anyone could throw over some advice.

I have this blueprint working so far with a boss -

(Change camera and player rotate function)

This blueprint has been made on the playable character, linking with the function from within the boss blueprint. So I’m trying to link all of the enemy types of characters into a blueprint interface class “AllEnemyCombination”, inside this I have just made a default input boolean / output float, and linked it to all the enemy class blueprints. When I go to use this, my boss has a function script attached to him, which looks like this -

The problem is I don’t understand how to make this function work between blueprints, as it’s blueprint specific for my mainboss. I need it to work on all enemy characters, as that is what is being called to see calculate the distance. The same applies to the setting of a nearest target, as this is a blueprint reference to the boss blueprint. Is there any way to standardise / make common all of these references? As at the minute thats seems to be where my blueprints are failing to connect to other enemies. Here is the parts in more detail and my attempt

  1. Original

  2. Attempt

If anyone is willing to help but needs more information, please let me know.

Cheers!

For my targeting component I created two main classes: An Interface called ITargetable, and of course, the Actor component called Targeting Component. This way I get have the ‘get target spot’ function return where to look if my ‘target’ implements the interface.

Thanks for the response Aesais, I’m still new to scripting so sorry if I’m asking silly questions.,. How did you manage to get the targeting component functions working? Mine all branch out to many streams as I’m trying to link them all to their own unique functions.

My Targeting component currently does three things:

  1. Gathers all ‘targetables’
  2. Keeps track of your current target
  3. Gives a hint as to which target will be targeted if ‘Set First Target’ is called

I have function that is ran on Event Tick named ‘Scan for Targets’. This function gets all actors that implement my interface, and then checks to see if they are in the player’s viewport. If the actor in the returned array meets the viewport condition, it then checks to see if it is within X range. If that condition is met, it then adds it to an array that I have cleared out at the start of the Scan for Targets function.

I have a function named ‘Set Target’ that handles which target is currently the main target. This is also saved off as a variable in my component.

And finally I have a function that rotates my player’s control rotation to a point in-between my character and the target.

Unfortunately I converted all of my code down to c++ recently, so I don’t have a node-friendly version at hand.

Maybe I’ll throw this into a plugin later.

Yeah it would be really useful as a plug in! I feel like I can hack together the system I’ve made, but I’m really falling down on linking it to multiple actor types. I’ve managed to put them all into an interface blueprint, but the problem is I don’t understand how a function can be made which can be used between all of these blueprint types, as that’s part of the targeting system I’ve made.

As you originally pondered, deriving all target actors from a common base class is a valid approach.

I know this is a little bit off topic, but this post got me thinking about the performance between GetAllActorsFromClass, GetAllActorsWithInterface and GetAllActorsWithTag. Especially since all three have a note “This is a slow operation. Use with caution.e.g do not use every frame”

Without utilizing one of them to find targets, one has to manually add them to some kind array everytime a new potential target is created.

Anyway , after some research, it seems GetAllActorsFromClass is significantly faster than the other two.

Basically, both GetAllActorsWithInterface and GetAllActorsWithTag nodes have to iterate over all actors, where GetAllActorsFromClass only iterates over actors of the class (and derived classes).

I wrote up a short blog with the details
http://www.casualdistractiongames.com/single-post/2016/09/15/Inside-UE-Source-FUObjectHashTables-the-magic-behind-GetAllActorsWith

Thanks OptimisticMonkey! I’ll have a good read over it tonight and try again! :slight_smile: