Ok so I know this has been asked before, but I want to get a measure on all 3 options I have considered and which is most optimal.
So in Event Tick i have some code which is blocked if not required by checking a variable first. But the same variable is what im setting,
So…
Check the Var then set if required
just set the var
use a gate
Shall i remove the checking step and just set the variable regardless as (when its needed) the variable will be set anyway. Is there a performance/optimisational benefit?
Or using a gate is this actually beneficial or is it just again another check that really doesnt matter and i set the variable regardless, removing 1 extra node of code for the times when the value changes.
Currently i mean a boolean, but this could be ANY variable in the future required in this manner.
Conditional checks (Validation) is always a “best practice” approach. Especially on Event Tick. Yet, every frame that condition logic is being run. This isn’t good unless you need to use event tick/delta time to do something important.
Overall though you shouldn’t be setting a variable through condition on Event Tick.
yes but a looping timer again becomes just as BAD an option when done on a regular basis (such as say more than 10x per second) for an important value that needs checking regular.
Everyone says Event Tick is bad, its not , infact any time sensitive work kinda has to be in there unless it can be changed using an event or other means.
Timers are better in many many instances yes. But using many objects with short intervals can have a negative impact on performance, especially if there are many actors in game doing similar tasks.
So its devil if you do, the devil if you dont. Im just trying to make the best of the situation in the most optimal manner.
NOW there is another option i have considered, and seen mentioned alot. Using REPNOTIFY on a variable. But mine never fire which leaves me back at square one.
If someone can point me in the right direction with REPNOTIFY I would certainly use that over a timer or event tick any day!
While reading this thread i kept thinking “why doesnt he just use a repnotify? Best option always if you can use it”
*Make your variable
*Set it to repnotify
*A new function should pop up ‘OnRep VARNAME’. Create the logic in here for whatever you want it to do. This will run every single time the var has been changed. I dont recal if it fires if you set it to what it already is tho (Setting a bool repnotify that is already true, to true again, as an example. Just throw a print screen in there and see if it fires)
*Set that variable anywhere you want and when its fired it’ll run that logic.
if you aren’t modifying per frame, then event tick isn’t the proper usage.
Rep_Notify replicates over the network. So if the server needs to change or does change the value, then you’re sending a packet on each change. Just an FYI.
Yet, rep_notify doesn’t handle conditional logic changes as per your OP.
So in Event Tick i have some code which is blocked if not required by checking a variable first. But the same variable is what im setting
e.g. If True → Set False.
Rep_notify will only execute logic on a change (Setting).
In the above example “If True → Set false”, on change to true the rep notify function will be called. If you then set it the var to false, it’ll re-call the rep_notify function again.
Proper usage is determined case by case. Devil is in the details.
Yeah the repnotify (I was led to believe anyway) should be able to work on a single payer game to notify of a value change. which is what i need, the code i then run will then change something else if you get me
So i detect a change in a boolean, then set some other vars or run some other function etc.
But the repnotify function never fires.
Like i said I was lead to believe repnotify works on the local client AND in single player. And thats what I really need.
Maybe i wasnt clear in the original post that im NOT changing the same variable im checking. Im modifying other vars and/or running some other code, and it is time sensitive whence the tick.
running timers on say 50 or 100 (or even 1000) actors in a time sensitive manner means many timers running at possible at least 30 times a second. which again I believe then increases load and lowers performance on the timer manager.
if i could get a notify event on the variable change this would be WAY the best option.
So if it works on single player be great
Do you have discord? If you do, perhaps a screen share so i can visually see what you’re trying to do will help to figure out why the repnotify isnt working. Else you’re gonna need to post some screenshots of everything
Thanks for the offer, my issue with repnotify is that it only seems to work when the actor changes the value itself (in blueprint code), and not if it is changed from another actor that has a stored reference. (doesn’t work if the value is changed in editor details panel at runtime neither!)
As repnotify creates another function anyway, I just changed my practices and instead of setting the vars direct I use a function to set them (or custom event) as it serves the same purpose to repnotify.
Which brings me back full circle to my original post.
Should I really add extra code to check a variable before setting another in on tick? (and yes time sensitive variable) or should I just set it anyway? Or the use of a gate surely is the same as checking as it again adds another extra bit of code when really does it matter?
Am I overthinking it? is the overheads negligible?
Just a note to those reading and agree with @Rev0verDrive about not using event tick, I do stand by my original quote that sometimes timers are NOT the best way when checking or performing code that happens EXTREMELY frequently. That said careful use of the event tick is needed for sure. Both Timers and Tick have their place and sometimes it can be blurred. But I agree with @Rev0verDrive , best avoided where possible.
Self or Authority needs to change the rep_notify variable in order to have the function called.
Basically the actor can change it’s own variables, or the servers authoritative proxy can.
Replication is server → client only. Thus changing it locally will not replicate out to the server. Use a server rpc to change the variable. Your rep_notify will then run.
This applies to single player too.
Process is similar when changing the var on another actor. Server uses reference to change it.
I use timers to control rate of fire in weapon classes directly. High rates up to 1,000 RPM…on 100 clients in a multiplayer setting. I use them on many many many other things such as polling loops etc.
Timers are fine as long as you manage their handles correctly.
I feel with a few details about the actors you are working with…what exactly you are trying to accomplish. We could provide a better, more performant solution.
Yeah I do appreciate timers have their validity, 1000rpm is 16.667 times a second so not too bad and would benefit a timer.
TBH I am toying with using timers on the time sensitive things but a bit of testing would be involved to see if i can carry out the updates at a slower rate than each frame.
The question was in general mostly about “worst case scenarios” on time dependant updates either to vars or to fire an event or function.
So please dont think I am dismissing your points, all of them very valid and very helpful.
The question is “if I have to” what is best course of action optimisation wise , but again is it negligible?
Negligibility would be determined if the actor uses tick for anything else. Can it go dormant and turn off tick. If it doesn’t need tick for anything else it shouldn’t be on. That in itself can be a sizeable performance factor.
For multiple actors that need to run checks, logic etc at the same time (in sync) you can use manager actor that runs a single timer and dispatches (Event Dispatcher) a check call.
e.g. If I have 50+ actors that needed to check a state every 8.3ms, I’d use the above approach.
Doing it this way vs tick or timer in each actor would be a sizable performance savings.
frame times fluctuate constantly. If your calls “have to” happen at very specific increments and loop, then timers are pretty much the go to.
Optimization wise, Timer trumps tick. Tick has inherited overhead and should be default off on actors.
interesting thought the manager actor. But wouldnt the dispatcher add a certain amount of overhead? also the cross actor talk to update the vars also be additional overheads?
If they are tiny then this might be a better way to go i must agree
So thinking that way, the actual production style buildings will just be relaying information thats important when and where required and would only need to “hold” information if a player is say looking at their config/control screen?
I always passed on the idea of a manager actor, thinking alot of load on 1 actor could be bad for performance as it loops through, but as you said its the load on the cpu cycles thats the issue.