Issues with Activating Combat Mode with Line-Tracing

So, I’ve been working on a system that activates “combat mode”, whenever an enemy is within 800 units(?) of the player, and when they are an interface is activated to the enemy blueprint, having a “soft-lock-on” cone above their head. However, I am running this with event tick and I’m not entirely sure how else to run this. Also, I’m having issues with it constantly doing its thing, once it is in combat mode. Below is my blueprint and any help would be greatly appreciated! Also critiques would be great as well!

This is essentially supposed to be like the Kingdom Hearts combat system, where once you enter a certain distance of the enemy, the HUD changes color and new music begins playing. That is essentially what I am trying to go for at least.

CombatEnemyDistance = 800
MinDistanceToCombat = 0

You shouldn’t do this:
because you’re accessing a variable that technically doesn’t exist, because it comes from what is executed after the branch. Move the cast to before the branch, and you’ll be fine.

Not sure if that’ll fix your issue, but if it doesn’t let me know!

That certainly got it to work, however I am now having an issue where the Target Visual appears above both enemies’ heads. It should only appear over one enemy’s head and not multiple. Do you know what I should change in this to keep it from doing that? Here is my updated BPs:

Also, I realized that if literally any actor or static mesh interrupts the line trace, then it will set combat mode to false. Really annoying, and I’m not sure what to do to circumvent that from happening.

You can solve the LineTrace issue by using a MultiLineTraceForObjects, instead of a normal LineTraceForObjects. It will return a vector of hits, instead of just one!

Regarding your issue, when is the CombatModeInitializer function called?

MultiLineTraceForObjects will ignore obstacles in the way? Hm, I may give that a shot. The CombatModeInitializer is called on EventTick:

Not sure if this is where it should go, but I am still fairly new at where the most efficient places to put functions like this should be.

I just tried using the MultiLineTrace and it turns out I cannot break hit result with it, and I’m not sure what other option I have to use, in order to check if it hit an actor.

Edit: I actually just ended up setting the branch condition before distance from player check to use both true and false, because really it doesn’t matter, since this is only checking if the enemies are within a certain radius of you.

You can break you MultiLineTrace like this, you have to use a for each loop:

Well, my thoughts are, you you’re calling the Combat Initializer on Tick, it will probably activate only one enemies target visual at once, but because it’s being done on tick, it’ll actually do it for all available enemies in a few frames (so there is basically no difference between that and setting all the target visuals visible at once).
You should probably keep a local variable in your character that tells you whether any enemy already has a target visual visible, and if it does, don’t activate any of the other target visuals :wink:

Keep a boolean in your player character that will be true once an enemy detects/is detected by the player. Whenever that boolean is true, no other enemy can detect/be detected by the player (which is something you do in that same blueprint).

The thing is I thought about doing something like that, but I wasn’t sure how to go about doing it, since it takes in an array of dudes and I’m not sure how to tell the game “hey, BP_Example_Enemy_2 has an activated cone over his head, so you, BP_Example_Enemy_1, cannot have one.”

I am starting to get a little confused. Then again I have been banging my head against a wall with this one for several hours, so that may be why XD I am struggling with where specifically I’d put it.

In third-person-character I have everything running on event tick, here:

And Soft Lock On is part of Third-Person Character, here:

And within the Enemy Blueprint there are several events for different situations, such as determining combat mode, and the hard-lock on, which turns the soft-lock on gold instead of arrow-blue:

In which blueprint is the logic you just showed in your screenshots?

You have to use your TargetSoftLocked boolean to stop an enemy from being soft locked.
Try to think about how the code is gonna flow, what variables are gonna be changed to what (specifically the TargetSoftLocked bollean). Your setup doesn’t work, because if an enemy is already locked on, it will simply say that no enemy is locked on and execute the code regardless:

What should be happening is, if the boolean is true, don’t do anything except for checking if the enemy that was locked on is no longer locked on. When it stops being locked on, then you set the boolean to false.

If this logic confuses you, maybe you should take a step back, or maybe look at a couple tutorials.

Focus on doing one thing at a time. Do one part of your system, then another one, then another one, because if you don’t, when you test it, it doesn’t work and you don’t know why, and then you have to look at a bunch of stuff that you did and you don’t know what works and what doesn’t. So be careful with that, especially if you aren’t comfortable making these kinds of systems.

I’m not telling you to stop! I’m telling you to take a step back and do things one at a time :slight_smile:


I believe I got it working now! There are some other issues in regards to the hard-lock on system, but that should be fairly easy to rectify compared to this. But, if you see anything wrong with this setup in the screenshot, let me know! Otherwise it only sets the visibility for the cone once and that’s all I need. But, who knows, I may come across something dumb along the way.