Blender Logic Source I've been working on my own python library to assist in usage of UPBGE (importable player setups, auto-split screen, handling input in a more natural way, some procedurally generated objects etc), but to optimise it so things only update once per tick, I have ended up requiring a tick counter.

So far, I've been using an always sensor connected to a script that adds "bge.logic.tick_no" to the mix, so you can access it from anywhere else easily. I know it should be using "bge.logic.globalDict" instead of going straight to bge.logic, but I wanted it to feel like it was part of the engine as opposed to something strapped onto the side of it.

I was wondering if there was a way for me to edit the source code to have blender just add a tick to the overall tick number each time it ticks. I know C++, but cannot really make sense of what does what, or where it should go in the source code of UPBGE, even with the help of the documentation. No clue where anything running in the mainloop would be.

Any chance someone could provide some pointers?
Without using a script, you can create a tick count property and use the property actuator to increment it each frame. With the always sensor you can set the frequency (now called skip) to trigger the update every frame, or two frames...



If you place that in a common object that is always in the game, such as the ground, when you want to know the tick count in a script you can get the ground object from the scene.

scn = bge.logic.getCurrentScene()
grnd = scn['ground']
tick_count = grnd['ticker']


For forking your own version of blender, you will find the main loop at the bottom of wm.c. You can add a property to the GameData struct in DNA_scene_types.h, then add it in rna_scene.c to access it via python. Note that changes to any structs need to maintain a multiple of eight bytes in length for alignment, builds will fail if you don't get it right, and moving any existing properties will break reading blend files. It has been a while since I looked at this so I may be missing a change needed, start here for info about changing the data structures.