I'll explain the steps to reproduce the most simple example to allow to update a shape key value from python within the game engine. This is supposedly only possible through an armature object.
- start with a new blender file, use the cube that is provided by default
- add two shape keys, basis and key1
- select key1 go in edit mode and scale the cube object to half of its size and exit edit mode
Now i got a cube object with shape keys.
- add an armature
- shift select armature and the cube object
- hit ctrl-p and select "Armature deform -> with empty groups" from the context menu
- select the cube object and select "Value (Key 1)" in "Graph Editor-> Drivers"
- under "Drivers" properties
- select "Avaraged Value" for "Type"
- set "obj/Bone" to "Armature" / "Bone"
- set "Type" to "X Location"
- set "Space" to "World Space"
Now if I change the X location of the aramture/bone, the shape key changes its value and is represented in the mesh in the 3d view.
My problem arises if I try update said location from within the game engine. The cube object does not change it's shape when i change the X location of the bone.
I added a new script called "shapes" with the following content:
import bge controller = bge.logic.getCurrentController() owner = controller.owner if not "init" in owner: owner["init"] = 1 controller.activate(controller.actuators["Armature"]) x = bge.logic.getRandomFloat() owner.channels["Bone"].location = [x,0,0] print(owner.channels["Bone"].location) owner.update()
- select the armature object and switch to "Logic Editor"
- add an "Always" sensor with activated "True Level Trigger"
- add a "Python" controller and select the "shapes" script
- add a "Armature" actuator with "Constraint Type" "Run Armature"
- now connect those three boxes
The script chooses a random float value and updates the location of the armature accordingly. I can verify that the location is updated by creating a simple object and parenting it under the bone. The simple objects position will follow the position updates of the bone.
The cube object however does not change it's shape. My simple example can be downloaded.