Update data without using Event Tick

Basically I am trying to get the Leader to levelup when CurrentXP is equal to XPtoNextLevel, which works fine if I have the LevelUp function being called with Event Tick. Now I don’t want to run the function every tick, I rather run it when CurrentXP is equal to XPtoNextLevel. I looked around and it seems the best way to do this is through Custom Events - but I don’t know how.

LevelUp Function:

Event graph where I call LevelUp Function with Event Tick:

Newlevel Function (This is me trying all sorts of things to update without using Event Tick. I don’t need this for the final product because it doesn’t work; in other words this is me trying to solve the problem I have):

Some more stuff I’m trying:

Do you think that it would be better (more optimized) if I just had it setup where after Leader kills someone he gets XP and there in that event I have it check to see if Current Xp is equal to XPtoNextLevel, instead of having it be checked in all the stuff above (Levelup system)?

If I were to do that, should I put the XP code in the Leader actor or in the enemy actor? I can have it where when the enemy dies, it checks to see who killed it, and if Leader killed it then the leader gets XP. Or in the Leader, I set that he gets XP when he kills enemy

In programming common practice is to check state of varable when it is updated insted using timers, ticks and such as it’s only wasted preformance. So create function like GiveEXP, which will give EXP to player and in that function check it’s time to level up, if it is level up. Ofcorse by doing that you need to remeber to use that function to give EXP not using set node, or else check won’t happen

You may have more functions like that operating EXP in diffrent ways and check diffrent stuff, in such case it good to seperate checks in sperate functions and call them when any modifications to varable happens, in case of level up you would place check only if varable is increased.

This practice is a reason why in UE4 APIs you use set get functions (nodes in case of blueprint) insted of operating varables in engine directly (which you actully can do in blueprints too)

Wow, that makes a lot more sense that what I was trying to do! I’ll get to work on the new XP function, but I don’t really understand what you mean by “Of course by doing that you need to remember to use that function to give XP not using set node, or else check won’t happen” Do you mean I should create a separate variable for XP and set that instead of using the XP function?

No just don’t change that varable directly using normal “Set” node because that way your check code won’t be executed and character potentially won’t level up when it should be. Ofcorse in GiveEXP use “Set” node to update that varable just not outside ;]

I’m sorry, I’m not sure I’m following you. Did you meam that I should set the XP variable only inside the XP function, but nowhere else?

Did you mean something like this:
When enemy dies I run the XP function.

Inside the XP function I increase the character’s XP.
Also, the function then checks to see if XP is full (CurrentXP == XPtoNextLevel)
and if it is then it levels up the character.
Then, still inside the function, it sets XP back to 0.

Something like that. Simply if you use normal “Set” will just set varable and thats it, so use “GiveEXP” to increse EXP

Also i think you should not zero EXP on level, keep them just check if EXP varbale cross specific value… but do as you wish ;p also i think it should be => insted of ==

Thanks a lot for the feedback! But wouldn’t ==> run every time (continually run) XP goes over XPTONEXTLEVEL even after the function is run, or it would only run once?

=> will return true if value A (XP) is equile or higher then value B (XPToNextLevel which i assume is value how much EXP you need to level up).

If XP would be 80 and player get 50XP value would incerese to 130XP, but XPtoNextLevel is 100 so if you would do 130 == 100 it would be false and you not get level up same as 80 == 100 so you need to do 130 => 100 which will return true but on 80 => 100 it will be false and everything works fine :slight_smile:

I don’t know why you saying if something runs once or twice, or conditional nodes just return true or false and what you do with that it depends on you

On level up you either reset XP as you wanted ot update EXPToNextLevel to new value, if you pick 2nd option remeber to do check twice or else player woud level up only once it get EXP if you would give him huge about of EXP to level up to more then 1 level

Oh yeah I get you now, I was just thinking that it would run more than once since Xp would always be greater than tonextlevel but now I realize that I have to increase XPtoNextLevel right after I level up the character so that it only runs once. I was mixing up the two options you mentioned. Thank you for answering all my questions :slight_smile:

One more thing, if you’re still following this, how would I do the second check?

"if you pick 2nd option remeber to do check twice or else player woud level up only once it get EXP if you would give him huge about of EXP to level up to more then 1 level’
Do I just put it at the end of the GetEXP function?