Okay I’ve written a little (game engine) python script to replace an objects mesh. It should be quite straight forward, but I keep getting that stupid SystemError. Heres my script:
c = GameLogic.getCurrentController()
act = c.getActuator("act_setMesh")
act.setMesh("Cube")
GameLogic.addActiveActuator(act, 1)
Okay the controller that calls this script has an Edit Object actuator called act_setMesh connected to it, and the actuator has ‘Replace Mesh’ selected. Oh yeah and I have a mesh called ‘Cube’.
Whenever the script runs this error appears on the console:
PYTHON SCRIPT ERROR
Traceback (most recent call last):
File "setMesh", line 4, in ?
act.setMesh("Cube")
SystemError: NULL result without error
What does that error mean? and how do I correct it?
Just a newbie guessing, but are you sure there is a setMesh method in your actuator? Do a “print dir(act)” and find out. Doesn’t that (terrible) error message happen when methods don’t exist, among other things? Maybe it’s “setObject()”?
edit: oops, no, it is setMesh. Tried to reproduce your problem but couldn’t. Using 225 on Solaris. I tried renaming Cube to Bogus, and putting Cube on layer 1 etc… I don’t know what your problem is. Nevermind
Okay another weird thing I’ve just realised, not only should that method work, but I’ve already got it working in another part of the game. But I can’t get it working with this object for some reason. I was just using the mesh name Cube as an example, its actually an alpha-textured text object, and I’m trying to use this method as a way of changing the text colour/font. Is there a reason that this wouldn’t work with text objects??
Are you sure the MESH is named cube, and not just the OBJECT? Make sure you have the names right, the actual mesh name might be “Cube.001” or something like that if you’ve built any of your objects with cube and not changed the mesh name. Often I get the mesh and object names mixed up, go to the edit window and you can see both names at once.
the name of the mesh that I’m trying to change it to is txt_COMIC_Red. I specifically named it that because its a text mesh, using the Comic Sans Serif bitmap font that I made using ftblender, and its vertexes are painted red. I know thats the exact mesh name, with capital letters exactly where I put them when I named the mesh. Maybe the actuator requires the name to be in small case?
OK Saluk just to let you know I got that problem sorted, and it had a strange solution.
Basically, in order to use Python to set the mesh that the edit object actuator uses, there seems to be 2 basic requirements that you must have in place:
The mesh that you specify in the setMesh() function must already be assigned to an object in the same scene as the object with the actuator. For example, its no use specifying a mesh that has ‘0 users’ at the start of the game, and its no use specifying a mesh that is only assigned to an object on another overlay or background scene. :-?
The script that calls the actuator’s setMesh() function must be the called from the object that the actuator belongs to. I was setting the controller as a global object by storing it in GameLogic, then trying to call the setMesh() function from another script called by another object. It seems that this isn’t possible.