- History of Unreal
- Overview of the Unreal Engine
- Unreal Engine Components
- Overview of Component Interaction
- Engine Components at Work
- Creating Your Own Worlds with the Unreal Engine
Overview of Component Interaction
Now that you know the basic components of the Unreal Engine, here’s how they work together to deliver an actual gaming experience.
Most games are driven by a game loop: a part of the game’s programming code that constantly repeats itself, checking for any input from the player and updating all aspects of the game accordingly (see FIGURE 1.16). Within this loop, the game engine repeatedly performs many individual checks to see what’s changed in the gaming environment. For instance, has a player moved? Fired his weapon? Taken damage? Have his enemies moved?
Figure 1.16 This diagram illustrates a basic game loop.
The game loop generally also keeps track of “generic” tasks. For example, it queues the graphics engine to redraw the screen, tells the sound engine to play any sounds that have come up, and sends data across the network. Typical game loops are designed “linearly,” which means that each cycle of the loop runs through its series of checks in the exact same order every time, and give each check equal priority. But, as you’ll see in a moment, the Unreal Engine’s game loop is a bit smarter than that.
The Unreal Engine uses an event-driven game loop. This means the engine contains a list of events that the various components of the engine needs to address. These events are created from many different sources, such as player inputs, data from the physics system, or communication between components. Everything is passed through the system via this event list (see FIGURE 1.17).
Figure 1.17 An event-based system
In Unreal Engine 3, each event is given a specific priority. Rather than updating every single aspect of the game during every game cycle in an order that’s “written in stone,” events are processed based on their importance. For example, you fire a weapon. The game loop recognizes this, then reacts by sending multiple new events into the queue, such as instructions to launch a projectile and play a sound. Obviously, the projectile’s launch is more important, as it directly affects gameplay depending on whether it strikes an enemy or some other object that must react to it. Therefore, the Unreal Engine gives the projectile launch a higher priority than the “noncritical” gunfire sound.