Need help with a simple aim lock system

Good evening, guys

I’m making a system via blueprints to make the player focus his aim on an enemy whenever he presses a button and (&&) there is an enemy around (pretty much every Dark Souls game has something similar). The player can’t focus if there isn’t an enemy around, naturally, but after I find the *first enemy in the game *(and only after, not before), the player now can turn on the aim lock even if there is no enemy around him. I just want to fix this, since the rest is working as intended. I’m using IsValid for this. My bet is that the IsValid is returning true, even if the variable I’m checking (CurrentFocusedEnemy) is set to None. But why?

Here is the blueprint section for this behavior

Thanks in advance!

UPDATE 01: I’m overlapping actors at the moment (simple cubes), does it make a difference? I’m not an experienced user yet, I have a Unity background only.

Anyway, I tried to use Pawns as enemies and now the IsValid is returning always false even if there is an enemy in the collider and the variable I’m checking is not empty.

Here is the blueprint section for this

If it was me…

Everytime an enemy enters your collision radius, add it to an array of enemies (this should be easier if all of your enemies are subclasses of a main enemy blueprint). If the enemy leaves the area, remove its instance from the array. This means when there are no enemies in the collision radius the array is empty.

When you press your lock on button, cycle through the array and get the distance to each enemy, find out which distance is the smallest and set that as your lock on enemy.

After that you will have to update your players movement and animation. And any other things you want to change.

You will also have to set up an event for when a locked on enemy strays too far away, as they will be removed from the array automatically, however you will still be ‘locked onto’ them.

The reason your blueprint isnt working is probably to do with collision settings, make sure your cube is an ObjectType = Pawn and the capsule collision overlaps ‘Pawn’ class.

Thanks for the input, Orkney. I did as you said and I think it’s more smooth/manageable now. But unfortunately, the problem remains the same, even if I do check if the array length is greater than 0, the function still returns true when the array of enemies is empty. That said, the player is still locking on an enemy that doesn’t exist either in the scene, the variable (CurrentFocusedEnemy) or in the array.

Thats very strange, try setting it so instead of greater than it is greater than or equal to 1. If that doesnt work your array definitely isn’t empty.

Is you player character using the same pawn class as your enemy? it will overlap with the capsule then. Try making a custom channel for EnemyPawn. Or only add it to tthe array if it ‘DoesNotEqual’ your player pawn.

Yes, the player character is a Pawn, but the collider is just in front of him, so it cannot collide with himself. I did set to be greater or equal to 1, and still doesn’t work. I’ll upload a picture for you to see the bug being reproduced in-game.

combat_trigger.jpg