Trying to generate a list of targetable enemies based on sphere collision

I’ve placed an enemy in my scene, I have sphere collision on my character, I’ve created a widget with attack interaction buttons, and I want those buttons get a list of the enemy actors in range. So it would be Select Action>Select Target from list>Character performs action.

My blueprints have a lot of spaghetti from everything I’ve been trying to make it work so any help or advice would be appreciated

Hi,

Try to create some variables in parent BaseEnemy. Like

ID(Name) = FireMage
Level (Int) = 3

etc.

When you create enemy archetypes do inherit from BaseEnemy

and make their behaviours, ID, Level etc. whatever you like.

Then

OnActorOverlap->CastTo(BaseEnemyBP)->AddToArray(EnemiesAround)

ForEach(EnemiesAround)->GetID

UMGButton(OnClick)->Find(EnemiesAround->ID = ButtonID)

Let me know if it helps

So I added a name variable(I had this as a string) to the parent enemy class and set the variable on the child class

Parent

image

Child

Created the event ActorBeginOverlap on the parent player character following your direction to the for each loop but I’m not seeing how to get the name variable piped into the text box that makes up the listview component

I have a function from other guides/topics I was looking through that is supposed to pull the name from a list structure which I’ll probably have to change

I feel like what you were suggesting is going over my head lol

Yeah on your list simply in that UMG need to access them. Here is a step by step;

I created a base enemy character, made a variable ID

Created some child archetypes

Edit their IDs

Added a Widget in my character begin play

Cast to owner pawn and get ThirPersonCharacter, then I bind to its collision sphere events in the widget itself. Created a TMap variable (BaseEnemy_BP, Name)

Made an event like this and called on Overlap begin end. Also in its end called and updated event. You can make a function if you prefer.

Added a list view and created its entry class.

Entry with text and BG

After I simply do change text in the list entry. One thing to remember about ListView entries are instanced and dynamic so you need to access in our create before hand. Else changes won’t be reflected in instanced widgets.

Also made a Selected function to see if objects in the list can be controlled, added overlay material to demonstrate.

Result

This works exactly as advertised but it made me realize I need to change my logic with my widgets.

After setting it up as you have shown I was still running into issues which made me think it might be because I have the game set to a pause state when accessing the attack/target menu and that might still be the case but, I realized I wasn’t actually creating the widget until I’d already overlapped the enemy actors and therefore had no on overlap begin event to populate the list to begin with lol

So I’m going to rework the widgets to create on begin play and be collapsed then change the call events to open the widgets and see if it still works while paused.

Many thanks!!!

1 Like

Hey there, sure thing! If you realise something can be better why not.

Not sure about your game but I feel maybe its something TBS. If this is a core mechanic, I would suggest having the actors/enemies around at all times available in some component or some class that UI can query and display it’s necessary elements.

Me putting overlap events inside the UI is just an approach and its not truly wrong or right. Can be wrong depending on the game systems available.

If this was a TBS I would keep actors enemies all in a seperate class (UCombatTargetables) and let UI talk with it as observer. Call its functions like AcquireTarget, OnTargetSelected from UI but would escape coupling gameplay logic in UI. Since it can change, carried or used by many systems, better to think, If I delete UI completely can the game still function.

For pause, things can go wrong, since some actors tick in paused not tick, pausing the game is not always the best but maybe you can consider time dilation custom can be a better option sometimes to avoid some nightmares.

Happy developing!

My end goal is something along the lines of an ADB system like what you see in FF12 or Dragon Age Origins. I wanted the pause to give some breathing room with decision making, of course time dilation could work too similar to how the FF7R handles it.

I’m still very early into it and trying to learn best practices but now I’m one step closer to making it exist lol.

On a side note, how did you get your blueprints setup to use angles for the traces instead of curves?

I use a plugin called electric nodes, quite handy plugin, makes me work in peace with blueprints. However you can also edit editor settings for splines use direct lines etc, if you don’t want to use a plugin.