RPG Battle Target Help

Hello all,

I am moving onto my battle tutorial and following this tutorial series on a turn based combat system. I am on the target selecting and attack command part, but am attempting to do something a little bit different from the tutorial by making it so instead of a target list, you can click a widget to do your attack. However, when you click the button to do the attack, my enemy character does the animation that my party character is supposed to do.

I have 6 BPs for my characters, a unit base, two children of that BP called “party unit base” and “enemy unit base”, then a child of the party unit base which is my party member, and a child of the enemy unit base which is the enemy.

I believe this problem stems from the fact that when I click the basic attack button, I cast to the battlePlayerController and call a function called EnterTargetingMode which casts to the game mode, then calls a function within my EnemyUnit Base to show the visibility of the widget component. I believe this is at some point changing the unit character variable to be my enemy. I have tried setting the unit character during my combat components start turn function, and cannot figure out how else I might change it back to the party unit after the target button is clicked.

Screenshots and the tutorial are provided, and any help is appreciated! I am a lot less of a developer and more of an artist attempting to make videogames in my free time, so a lot of UE5 is very new to me. If you need any more information or screenshots I’ll be happy to provide.

Can you show what is calling Execute Attack in the Combat Component? It seems like the combat component you are calling execute attack on might be the incorrect pawn (the enemy, as you mention)

That would be the target button widget that spawns on the enemy. What your saying makes sense to me… in what way can I make it so the target button merely decides that this enemy you clicked is the one your targeting?

You need to set that TargetEnemy to the correct enemy. Do you have a way to click on enemies? If not, you will need to Trace from Camera to world. There are a few tutorials that cover getting whats under your mouse cursor. Then you would pass that to your TargetWidget to set the TargetEnemy.

Edit: Sorry I just read it again and you are spawning the button on each enemy. In that case, when you spawn this widget, have the TargetEnemy be Expose on Spawn, and pass in self to that widget that you spawn. Either way, that enemy needs to get their widget, and set TargetEnemy to self.

Depending on your setup, your enemy shouldn’t be the one plugged in to execute attack… To me it looks as if you mean to execute attack on the player since the montage is played in execute attack. In which case I would say the button could just reach into the player → combat comp → execute attack, you’d need to set a reference to what target you clicked so the combat component knows which enemy to attack. Seems like your naming for targetenemy should actually be: who initiates the attack… not the target

I am not exactly spawning the target widget onto the enemy, it is a widget component that I set the visibility on when the player enters the target select state. Which I believe I did what you mentioned on the edit within that function as shown, but let me know if I am misinterpreting that.

As for the execute attack, I get no error and the animation plays on my enemy with “target enemy” as the target. Meanwhile when I have my party unit in that target instead nothing happens and I get the error I screenshotted below.

image

After tinkering for a few hours, I got it. I had to make a new variable in my battle controller and I called it “currentlyactingcharacter”. From there on my start turn I get the owner of the combat component, set the unit character, then cast to my battleplayercontroller to set the currently acting character as the unit character.


Then, when I pressed the target button, i had to cast to the player controller again and make the target of the execute attack the currently acting character.

Thank you for your help and time!