From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

BGE Python scripts migration

This page documents the necessary changes to port a 2.4x BGE python script to 2.5 and newer. It doesn't claim to be a complete list, but at least something to start with, when porting a game.

Important changes

  • 'OB' is not part of an objects name anymore! (Take care about [2:] removals of those two characters)
  • Many functions now return mathutils objects like Vector and Matrix. Make sure to copy them in case you edit them or the changes will be applied to the object you got it from too.
  • Blender 2.5 has a completely new sound system. More infos to come.

Modules renamed!

Most of the modules got renamed, some old names still work, but the question is, how long, so you better migrate:

  • Mathutils => mathutils
  • GameLogic => bge.logic
  • GameTypes => bge.types
  • GameKeys => bge.keys
  • Rasterizer => bge.render
  • PhysicsConstraints => bge.constraints

Mathutils changes

Mathutils got a lot of changes. Very important is that all angles have to be expressed in radians rather than degrees now.

  • Degrees => Radians (note for Vector.angle() and Rotationmatrix for example)

Other API Changes:

  • The Vector constructor awaits the values in a list now, rather than as seperate parameters. Vector(1, 2, 3) => Vector([1, 2, 3])
  • Rotationmatrix uses an uppercase axis character now. 'z' => 'Z'
  • AngleBetweenVecs got removed => use Vector.angle(Vector)
  • Rand has been removed, use Python's random functionality. Mathutils.Rand(low,high) => random.uniform(low,high)
  • Vector.reflect() had a bug before, make sure to test your scripts in case you used this function before.

Python 3.1

Some changes you will have to make come because of the new python version. For example:

  • print() has to be called with parenthesis. print 'Hello' => print('Hello')
  • has_key has been removed, use the in-operator. a.has_key(b) => b in a