Problem setting action using python

I’m having some trouble setting the action for an action actuator using python. It’s for animations for getting in and out of vehicles. Here’s the part of the script that sets it:

if nearVehicle.positive:
            vehicle = nearVehicle.hitObject
            vehicleType = vehicle.get('VehicleType')
            enterVehicleAnim.action = vehicleType + 'Enter'
            exitVehicleAnim.action = vehicleType + 'Exit'

The VehicleType property (in this case it’s kestrelPilot, ‘kestrel’ is just the name of the vehicle design I found on is used to get the enter and exit animations (kestrelPilotEnter and kestrelPilotExit).

It worked perfectly for the enter animation, but for some reason it doesn’t work for the exit animation unless the kestrelPilotExit animation is selected in Action Editor of the .blend file or the animation is put in the action space of the actuator. Otherwise the console gives me an error message saying the action wasn’t found, even though print(vehicleType + ‘Exit’) always returns kestrelPilotExit when I tested it. If I have to I’ll use different actuators for each vehicle action, but I want to see if I can fix this first.

I first noticed this when I started using Ubuntu instead of Windows XP. I wanted to see what Ubuntu was like so I set it up so I could boot either Ubuntu or XP. From what I could find through testing different things the problem is not from the script, but from the .blend. I made the enter animation when I was still using XP and the exit animation when I started using Ubuntu. Both times I used Blender 2.57.1, the only difference being the operating system. The same error occurs on both systems and with earlier versions of Blender 2.5.

Could someone help with this? I’d attach the game, but it’s not one .blend file, it’s multiple files linked into one level and I don’t think I can upload that.

Are you currently using the latest version of Blender? Just wondering.

As to the actual problem, I don’t know if this is the solution, but perhaps you should just do:

vehicleType = vehicle[‘VehicleType’]

Accessing the variable with get() may have been the problem, because if there’s an error, the returned value will be None, and that could have been the problem if the returned value is None.

I am using the latest version of Blender, and using vehicle[‘VehicleType’] didn’t help. I also tried bypassing that altogether by using:

exitVehicleAnim.action = ‘kestrelPilotExit’

This should have worked because that’s the correct name, but it didn’t. That’s why I think it has something to do with the animation itself. I’ve tried making a new animation, but it still says it can’t find the action, even though it should be able to and the enter animation works fine.

Try setting the action beforehand and printing out what the action is before you assign it to see what it should look like. It would seem like you’re doing everything correctly, so I’m not sure what the problem could be.

Yeah, I’ve done that too. It should be working, but it isn’t. Could the file be corrupted? Is there an easy way to transfer everything to a new file?

Appending everything through the File menu should do it.

So I just discovered something interesting. Since my character is a group I could just append it directly into a new file, but when I checked the animations I noticed that kestrelPilotExit (the one that hasn’t been working) wasn’t in this list of animations. And since the group is linked into the level where I test everything, that would explain why the game couldn’t find the animation. Somehow new animations are no longer being added to the group, and thus are never being detected within the test level. This must have started when I began using Ubuntu, since that’s when I noticed the problem.

So that’s sorted out, but I still have no idea how to fix this. Any ideas?

Hey, try using the F-Curve fix in the Help menu - maybe that will help. Don’t save afterwards unless it works, though. Also, see if any new animations created can be seen, as well.

I can only speak for 2.49 but I assume it is the same in 2.5x.

A group contains everything that belongs to the objects of the group, but nothing more.

That means:

  • textfiles that are not referenced by a script controller (script mode!) are not part of the group
  • actions that are not referenced by the object or an action actuator are not part of the group

How to solve this?

This is easy but could become a pain.

Text files:

Set up a script Holder:
Is object that is part of the group (optional: can be removed after game start) and references the text file

  • add a Python script controller that references the text file. The controller does not need to have any links to other logic bricks


set up an Action Holder
Is object that is part of the group (optional: can be removed after game start) and references the action

  • add an action actuator for each action you want to have in the group. The actuator does not needs to have any links to other logic bricks.

The pain is:
You have to setup that for each action. The good thing is: If you rename an action, the reference is renamed too.

I hope it helps

Thanks Monster, it works now. I didn’t know animations weren’t added to groups. It would be helpful if they were.

The problem is, that Blender can’t know what actions you want and what actions you do not want in you group.
Importing all actions would create an awfull large data block.