How can i fix a skill which uses 20 mana and works fine until the very last 20 mana remaining which then it skips the attack ?

I have this skill that uses 20 mana for 1 attack. If i have 100 mana that means i could then attack exactly 5 times and the mana will be then depleted and down to 0. But what happens in reality is that i can attack 4 times and on the last 20 mana that the character has it dont attack 1 more time but instead it uses the last 20 mana and skips the attack animation. How can i fix it maybe with a branch where i say “can attack” if mana is equal to 20 or greater ? I tried many differnt approaches like this but it aways failed :frowning:

The Mana logic is in a component then added this component is added to the character

and the skill is on the character which calls the decrease mana function and uses it on the skill

Any help will be really appreciated i have this problem scince months which i every now and then revisit but could never solve

IMO somewhere there is the condition Mana > 0 when it should be Mana >= 0.

i just updated with pictures and i have greater or equal branch is that still correct up there or do i have a flaw somewhere ?

From the image I see there are several branches that check the remainding mana even after changing the value.

IMO you only need one branch to check (CurrentMana - SkillCost) >= 0.0: if true then subtract and directly do the rest. You don’t really need any other branch to check the mana since it’s a one time operation where the result will always be above or equal to 0.0.

There is a chance that because of float rounding errors you might get a value slightly less than 0.0, but that is a problem you shouldn’t be concerned with right know, IMO.

I tried with 1 branch then with 2 nothing helps. Can you point me more precise where exactly how and where i need to connect them.

If i do 1 branch like here mana cost is set to 20 and “no mana left?” branch this to true then it cannot attack or if false (mana is left) then it attacks 4 times and skips the last 20 mana but uses it and mana is then at 0 if press attack again it comes the message what my character say “no mana left/ i cannot attack…” stuff like this but same problem

Do i need to change the “no mana left?” condition here maybe (is set if mana is less or equal to 0 then “no mana left?”

(CurrentMana - SkillCost) >= 0.0 should be here:
image

You shouldn’t need this:
image

if i make it like this now
bandicam 2023-06-26 15-23-22-361

result is not attacking at all… My character says at full mana now directly “mana is too low cannot attack”

If i dont need the last branch on your second screenshot where to hook up the return node should it look like this ? Anyway is still not wanting to attack at all is if i had no mana anymore even if its full
bandicam 2023-06-26 15-27-02-894

If i change it like this at the end my character its attacking non stop and the skill dont use any mana cost as well as the value is not changing and is aways on full mana now

If i plug at the end the branch back but this time with is greater or equal node (now at the start as well) is not attacking at all

Looks like it worked best as it was with less or equal then 0 then at least it attacked and stats where moving accordingly so for 100 mana 1 attack -20 mana and it showed correcltly 80 mana. I could repeat that until i get down to 20 mana then it skip last attack and fall to 0 then message comes if i press attack again - character say no mana left…

I suggest this as a pure function:

If true: Here I’m passing CurrentMana as a reference and changing the value dirrectly inside the function.

If false: Only return false, do not change CurrentMana value.

This is how I tested:

Result:
image

1 Like

I get awso the same result. When i use my skill my mana goes from 100 then 80 then 60 then 40 then 20 then 0 and character say at 0 no more mana

Only that it not attack the last 20 mana but just uses it so code is working and display it correctly only why the attack is not doing it at the last 20 mana here how it looks like

There has to be another branch after this that’s doing the same check again.

Edit: with this delay if you click fast enough can you consume the mana before the second attack?

yea its the same branch where it has the same condition “no mana left?” which if is true then no mana is left and cannot attack and after cannot attack comes the message. If its false then branch from no mana left? go to “can attack”

So the “no mana left?” if its connected to “can (not)attack” and works correctly acctually the attack im doing on the video should awso work mana cost is at 20 and i have 20 mana left but never uses it only depletes it without attacking

no i cannot consume befor attacking the delay is only for the message if its not there and i click fast with 0 mana character say way too fast “no mana” or cannot attack" which overlaps so when she say no mana it awready say the next message which sounds broken then

https://streamable.com/07n8xk

If you only do the check once like the image above then the very last consume souldnt be a problem. If there are no other branches checking the available mana then right know I think this is your main issue.

This is all taking into consideration the start value of mana is 100.0 and the skill costs 20.0.

Yeah there is only this 1 branch and the mana shows correctly and depletes until it hits 0 mana then the message comes no mana left so this works as it seems. Mana cost value is set to 20 and is depleting correctly as well only when its at 20 then is broken still dont know what to do with it. is it not fixable as it is right now somewhere in the stats component maybe ? i tried the is greater or equal there but then it dont work anymore

I suggest you try this: after the consume mana function only have 2 print nodes, one on true and another on false. Disconnect everything else. If the print on true executes 5 times (5 clicks) and the one on false executes on the 6th click and after means the problems is elsewhere.

Let me know how it goes.

Ok i just try to replicate this on another skill and it seems it has the same issue. When try to lower the mana cost to 10 then it works 9 times and the last time it awso just skips it…

here is the branch result

so it looks like i can use 90 mana and the last 10mana or whatever the skill’s mana cost is then last 10 or 20 mana its counted as “no mana left then”

Ok! That’s good.

Where else is the mana value being checked? Are you using GAS or any plugins to manage the skills?

no i dont use gas system. My stats are on a component self made stuff from tutorials acctually. And everything works except this one all the stats like xp health points and so on work flawlessly so far

I think just doing this will solve the problem

No extra checks inside.

The reason last one won’t work because On the basis of “DecreaseMana’s” Result Player is attacking and when the mana reaches 0 in the last attack the ‘Branch inside’ returns false

When This Happens The Branch Below Discards The last Attackk

It is better to rename the output value of the DecreaseMana Function to CanAttack which will remove the ambiguity in your Blueprint and prevents this logical error

1 Like

So what do i do with this last branch there ?