Raycasting for detection, controling the skeleton

Hello everyone, I am learning about Raycasting and I was wondering if there was a way to use it to detect enemies within a range. My thoughts would be to set up the enemy to have a variable that the play character searches and if the value is above a certain amount it would attack or trigger something like the start of a battle. (Que battle Music, Draw Command HUD, Draw Party HUD, etc). The game I am designing is more of an Action RPG and I am inspired by Final Fantasy 15 and Kingdom Hearts.

My goal is to place a sphere component over the Player’s head and Raycast from there in order to determine if what the character’s actually looking at is an enemy.

Another thing is, if the above is possible, is there a way I could make something catch the character’s attention? So maybe he runs by a home, and his head turns to it? (Not full Body)
I think that would help make exploration more real, as well as battles, and more.


Would it be possible to use a trace to determine if the object hit has a certain function or component that would be labeled enemy?

Yes, if for example, from your break hit, you cast to a master character then you’ll can have access to its variables, functions, custom events, so if you set a bool “enemy” in your character master, you’ll can know if it is true or not.

I tried Single Line Tracing from my Player Character, but it’s not hitting anything even when I face the enemy character. I have the Line Trace to Channel node connected to a Cast to “Goblin” Node and within the Goblin I created a Variable called Faction which is set to False which then should bring up the Battle HUD Widget. True would mean that the Goblin was friendly. Am I missing something?

Try a linetrace for objects / use break hit and from it directly cast to goblin without return value check. Then drag your vaction variable and try to print it. It would be ok