I felt like my previous post deserved at least a little bit of a breakdown as to how to implement the game tick. If you have any desire to create an RPG-derivitive of some sort and your characters regenerate slowly over time rather than instantly, the game tick is your best friend. If you don’t like the idea of processing everything at the same time, you can always implement multiple ticks to handle different aspects of the update. Or use some type of tick logic on individual effects. There are many ways you can go with something like this, but deciding how you want to update your characters is very important.
I figured it would be worth it to run through the breakdown of how this tick is set up so that anyone that wanted to follow along would not need to just look at the screenshot and just blindly implement it hoping for the best.
Event Begin Play issues a call to Game Tick, which is a custom event. One improvement to this might be adding a Switch Has Authority node so that you don’t make unnecessary calls. That node is on the Game Tick, so regular clients will get no further anyway.
GameTick first makes sure that the entity trying to create a new tick is the authority (wouldn’t want peons defining their own ticks, right?). After that it seeds a new random stream. I have no interest in repeatable random, so the stream is set up to get a new random each time. I still need to fix the seed variable because it has no logic to regenerate every time, but the framework is there. It then gets a random integer between the min and max variables using the random seed and sets the CurrentGameTick value.
Next, EventTick is obviously firing off all the freaking time, but we really don’t want to update that often. To fix that, we give it a sequence (so we can also process other stuff later) and check if the CurrentGameTick is not equal to 0 (ensuring that we have at least set it once). If it is something other than 0, we set a Delay for the length of time. After that delay, we execute another custom event, ProcessTick.
The last step here is to actually process events for the Game Tick. ProcessTick should contain whatever callouts to process things that you want to do every tick.
Finally, a quick look at the variables used here
Ignoring DefaultSceneRoot, the GameRandom is a VariableStream, while the rest are Integers.
There you have it. Hopefully an easy-to-follow implementation of basic game tick functionality in your game, using only Blueprints 🙂
As a recap:
1) Begin Play - Call the Game Tick
2) Game Tick - Create a new value in some range based on random seed
3) Event Tick - Wait for Game Tick time
4) Process Tick - Do stuff
Let me know if there is something here you would like me to explain more clearly 🙂
Recent Comments