Download

Sevrerside Tick Event

Hi all :slight_smile:

I have a hunger/thirst system that decays over time. The way I’m doing this is by building up the elapsed time for each frame to the decay rate, then taking off a chunk of each of the needs:

My question is, how would I make this work properly on a multiplayer game? My idea was to call the ‘Tick’ event for each server tick, but I’m not sure how to correctly set that up. I’m working through some tutorials but information is somewhat sparse at the moment. I’ve set the relevant variables to replicate but that doesn’t seem to be a part of the solution.

Also, if I’m doing decaying needs incorrectly or in a particularly inefficient way then I’d love some feedback on that.

Thanks a bunch!

Ah yes, sorry for the sparse networking documentation, but we’re working on it! It’s something particularly near-and-dear to my heart, so hoping to have a blueprint networking tutorial up very soon :D.

For your particular example, I’d probably do something like this:

This will make it so that every DecayDuration seconds, it’ll call your DecayNeeds function for you automatically. The “Has Authority?” macro will make sure that timer is only set and executed on the authoritative version of the actor, which should be the server. I don’t know what your DecayNeeds function is doing, but I assume it’s decrementing replicated hunger/thirst variables. If so, this should just work, while making sure only the server is actually setting those values directly.

Also, for extra safety’s sake, you probably want to wrap the actual setting of the variables in DecayNeeds with the authority switch too, if it’s also in blueprints.

That works perfectly! And so simple. Thanks a lot :wink:

No problem at all, glad it worked for you!

Underrated thread.