Tuesday, April 14, 2009

QBBT: Which Logic Bricks Get Used First?

You'd never expect a programmer to write code without any idea of which line was going to be executed first. Blender's Game Engine Logic blocks are a brilliant way to let visual artists "code" by connecting visual blocks together to create logic and AI in games. The funny thing is that almost no one learning the Blender Game Engine comes across anything that tells you which logic bricks will actually be executed in what order. This can make figuring out complex setups far more difficult than it should be. In a nutshell heres how it seems to work from my tests:

Basically it seems that blender starts with the list of actuators (the ones that make changes on the right) and works it's way down. In this case Blender tests to see whether to play the armature action first... then the message actuator, the state actuator and the end object actuator.

This is especially important to know if you're using the state actuator which switches which controllers (and thus which other actators) will be used from this point on. Obviously if your state controller switches an object to use a different set of actuators, the actuator you had set up just after it isn't going to be run. Also worth remembering is that an actuator hooked up to a delay sensor, while it may be examined first, won't actually be executed until the delay sensor has counted to the end of it's time delay. What happens if a delay sensor is still counting up when a state actuator triggers it? Good question.... to be answered in a future QBBT!

No comments: