BGE custom properties and other values

Hi all,

I’m still struggling with my facial animation and how to animate it from within blender.

Basically I’m looking for something which I can animate in blender and then translate to UV position with python. So:

  • Is there a way to access custom properties with python? (Note: not Game-Properties which cannot be keyed.)

  • Can I access bone-positions from python? And how do I get to one bone from the armature? Bones don’t seem to be children and I don’t find any other way to get there.

  • Generally: Is there some list/cheetsheet somewhere of which blender values can be accessed from the BGE?

Thanks in advance!

No, not that I’m aware of.

Not directly. If you know you’ll need to access a bone’s position in the BGE, you can bone-parent an empty to it before hand and then access the empty’s position in game.

The Blender Python API

  • Generally: Is there some list/cheetsheet somewhere of which blender values can be accessed from the BGE?

BGE is totally separate from Blender and BGE is not about modifying Blender values. Some things you can access but generally making things happen in BGE (such as moving objects, animations, deform, changing texture, particles, fluids etc) needs to be planned from scratch.

So even when you know how to achieve a set of actions in Blender, you will likely need to abandon the solution and start finding out about BGE solutions to it. You are probably best off asking specific questions and searching the forums for if anyone else asked about it before.

I’m still struggling with my facial animation and how to animate it from within blender.

Basically I’m looking for something which I can animate in blender and then translate to UV position with python.

Facial animation is often just shape keys and armatures making up actions you can play in BGE much the same as in animation. UV texture coordinates you can’t keyframe as an action for BGE as far as I know, but you can still move them manually with python script.

Thanks all! “No” seems to be the default answer to thinks I’d like to do lately.

The missing custom-property support in BGE is a pitty because it would form a nice interface to the blender animation system for things which are not supported directly.

@Cheetsheet / Blender API: I know this but it is missing some information sometimes. E.g. there is a description for “BL_ArmatureBone” but no info on how to access it. So I asked here. It would be useful to have some kind of cheetsheet / overview which blender settings are accessible in BGE and how they are mapped.

These are some ways to make facial animations:

A) Shapekey Actions
B) Armature Actions
C) Python driven UV-manipulation (see UV-Scrolling)

I’m not sure if that helps you in any way.

As Scheintod mentioned, you can access an individual bone of an armature via Python. An armature object in Blender is a BL_ArmatureObject in the game engine; it derives from KX_GameObject, and so has the normal KX_GameObject properties, in addition to special properties. So, in an armature object in the BGE, in addition to normal KX_GameObject variables, you have access to the constraints and channels properties, and the update() function.

You can access the bones themselves to set rotations and positions through the channels property. For example, you would use armature.channels[‘BoneName’] to access the bone, and then bone.rotation_euler to rotate the bone using a Euler (vector) after setting the bone’s rotation_mode. Then, you can use the update() function to update the armature to display the changes. I imagine this would probably be best done once per frame.

Here’s a quick example.

ArmaturePythonTest.blend (439 KB)

If you want to find out what things can do / what you’re working with, you can use print (type(obj)) to find out what kind of Python object an object is (for an armature, it would print out BL_ArmatureObject). You can take that information to the bge.types portion of the API and continue to find out more info. However, it’s nice to know that you probably won’t be doing this too much; there’s not too many types of unique object classes in the BGE (you’ll probably be dealing with 'KX_GameObject’s 99% of the time).

Note: You can find the position of a bone via its location property, but this will be local to the parent bone / armature object. So, you’ll need to do a recursive upward search to add in all parent bone’s positions, and then finish it off with the armature’s worldPosition to get the bone’s absolute world position.

@SolarLune: Hey! That is what I was looking for. Thanks a lot!

I had looked at BL_ArmatureObject already but didn’t realize that ‘channels’ means ‘bones’. Looking at it again I see I would have needed to read the whole paragraph to the end: “channels: The list of armature channels. Elements of the list can be accessed by index or name the bone” (But who has time to read everything? :slight_smile:

Now let’s see how this plays out. Thanks again!

As far as I understand the system: Channels are not Bones.

A channel belongs to an action while a bone belongs to an armature.
A bone can play the animation the channel describes.

Channels are assigned to bones by name - which is similar to the Vertex group to bone assignment.

This allows to use an action at multiple different armatures. Channels without corresponding bones are simply ignored and vice versa.

In the DopeSheet editor the channel can be even smaller - it is the atomic part of an animation (a single curve e.g. the X Location). I do not know if there is a detailed explanation what is named what.

Nevertheless: Yes search for the a channel with the same name as the bone name ;).

@SolarLune:

Now I have still a problem: If I run your test-file I get this output:

This bone is, relative to the parent bone position, at:
<Vector (0.0000, 0.0000, 0.0000)>
The base bone is, relative to the parent bone position, at:
<Vector (0.0000, 0.0000, 0.0000)>

That’s correct. If you (disconnect and) move the child bone, then the first vector would reflect it. If you move the base bone, then the second vector would reflect that. The locations listed for the bones are relative to the parent bone, or the armature object. So if the base bone is at position [0, 0, 0] relative to the armature object, then its location would read [0, 0, 0]. You would need to add the armature object’s worldPosition if you want the absolute location of the base bone.

Hm. Seems there is one more level of indirection. I get the null-vector for all bones. I have to move them in Pose-Mode to get different results. But hey, this is exactly what I need :slight_smile: