Tuesday, 3 December 2013

Benefits of Scripting and it's use in modern Game Engines

A few popular examples of General purpose scripting languages

Scripting is a powerful tool that allows a game engine to become dynamic and highly modifiable. This tool can drastically improve iteration time, and serves to empower content creationists among other benefits. In this blog I hope to explain what makes scripting so beneficial and give a brief rundown of how we'll be implementing scripts in my team's upcoming game.

Naughty Dog's take on scripting at GDC '09

Having a scripting system in place means that core game-play features can be implemented in a much simpler environment (Editor tools such as UDK, Unity or Phyre) without touching any of the C++ code. This gives content creators the ability to script complex scenarios, and most importantly manipulate component based game objects. 

That was a bit of a mouthful. 

What exactly does component based mean?

Examples of components in Unity

Using a component based model means that game objects are composed of an assortment of components, each with their own properties and scripts. This makes it possible to create highly complex objects with a variety of functionality, all within a simplified scripting interface.

In example 1, the AIComponent is pre-built before being added to the entity. The content creator can only select an AIComponent based on what was specified by the programmer. In example 2, the AI states are created as separate components and are modifiable by a designer without interference from a programmer.

From Damien Isla's GDC '11 presentation on scripting

Script can be seen as the glue that binds an object's components together. It tells each component what to do and how to communicate with other components and other objects. 

Component based, script heavy models have the benefits of being easy to use and very agile. They also help to easily separate the re-usable engine code from the game logic specific to any one project. This is extremely convenient for fast iteration and prototyping.

Working with scripting and component models in Phyre Engine:

Sony's Phyre engine includes a level editor tool that uses lua script to provide a powerful environment for content creation. In Phyre it is possible to instantiate and manipulate components in both C++ and script. The scripting component to Phyre is heavily emphasized and has been the main basis of everything we've implemented in our game thus far.

Here is an example of our main character's game object. You can see he contains a small collection of components which handle various tasks.

- Physics Character controller: Contains a script that handles physics based movement and collision detection.
- Character controller: Contains a script that handles animation according to user input and the movement output from the physics character controller. Interfaces with all other components.
- Animatable component: Contains the animation sets for the character exported from maya. Manipulated by the character controller component.

How scenes are constructed in Phyre:

Assets and Components are stored in the palette view where they can be customized.

Instances are created in the objects box, and are populated with components and assets by dragging them from the palette.

Here is a simple scene in our current work of progress game build. It's objects are displayed in the object hierarchy above.

Why not make everything in script?!

So far I've only said good things about the use of scripting. That's because it can be extremely useful and versatile as previously stated. However it does come at a cost to performance. Due to the nature of run-time scripting languages it may not be optimal to implement performance heavy tasks using script. Of course this is very dependent on the specific game engine/implementation and the strength of it's code/script relationship. Phyre engine in particular contains script access to complex code systems such as animation and collision detection. In fact, all of our animation, physics and locomotion code is currently being done in script.

That about wraps up my discussion of the power scripting languages add to game engines. If you have any questions or are looking for any specific information regarding Phyre engine feel free to leave a comment, it seems the documentation is sparse and the forums are non-existent.

No comments:

Post a Comment