bge.texture module, how to create unique storage obstacle from script for texture?

Hi, I’m new to coding and I have run into a problem using the bge.texture module.

In the api there is a sample script for changing textures which I was able to modify and use to change the texture on my object in the game. I gave the object a property which represents an energy level and set it up so that every time the energy level changes, the texture changes. This works great, but then if I make copies of my object I run into a problem. Whenever one of the objects changes textures, all the others do too.

I think the problem comes in here:

code snippet from the api sample code:

# the texture has to be stored in a permanent Python object
logic.texture = object_texture

# update/replace the texture
logic.texture.source = new_source

I think this means that each object is storing its texture in the same object, and when that object calls refresh they then all get refreshed.

So my question is, can anyone suggest how I might create a unique permanent storage object for each of my objects? I tried creating a variable and filling it with a unique string, but I couldn’t make it work.


The problem is that the texture module swaps out the texture for a different one, so any objects with the same material and texture will also be swapped out. While this is undesirable in some cases, it’s good for others. A solution would be to

  1. Create a new mesh for each object that you plan to duplicate, and create a new material.
  2. Create new objects with the texture that you need, then use replaceMesh() or the Edit Object > Replace Mesh actuator (can’t quite remember if that’s right) to swap the meshes out.

Thanks! I’ll try that.

Ok that worked well, thanks for the help SolarLune.

Here is a blend with the python script I wrote for switching meshes, just in case anyone else is trying to do the same thing and would like to look at an example:

I’m new to coding so any comments or suggestions for how to make it better/more efficient would be very interesting!