Changing textures independendly on multiple objects

First thanks to Monster and UnDEFER for getting me this far.
Also I have re-purposed UnDEFER’s sample blend from a 2010 post to illustrate this issue.


The example below uses three cubes that reference one of two scripts to change texture.

What I would like to happen is for the middle and left cube to turn to the same image and the one on the right to turn to a different image after a short delay.

What happens is they all turn to the same image and then the middle and right image turn to the same image.

It appears that this happens because the middle and right cube have the same starting image and so whenever a texture with this image is changed – ALL the textures with this image change.

Note that all three cubes have different meshes, different materials and different textures.
The texture is also never stored in logic.texture.

There are two scripts with the following code where only “path” is different (its hard coded in each script).

import bge    

def Change2(cont):
    
    owner=cont.owner

    matID = 0
    
    path = bge.logic.expandPath("//4.png")

    imageSource = bge.texture.ImageFFmpeg(path)
    imageSource.refresh()

    texture = bge.texture.Texture(owner, matID)
    texture.source = imageSource
    texture.refresh(True)

    #store texture somewhere e.g. at the managing object (this one)
    owner["tex"] = texture

QUESTION: Is it possible to override this effect to dynamically change textures independent of what image they start with?

ThreeCubeTexChangeFail.zip (96.7 KB)

Textures are stored as a pointer to a location in memory. So if you have two materials with the same image texture, those two materials will always be linked. The only solution (that I am aware of), is to give every object a different starting texture.

Maybe LibNew should get new Type, material?

sdfgeoff, perhaps I am misunderstanding but as i said I am using all different textures its just that the image for two of these different textures is the same. I recognize that the texture slot references the same location in memory but I was surprised that the image seems to do the same. Is that what is going on?

@BPR
Unfortunately Libnew does not seperate material.texture slots. If it did, it would be a lot more useful. As s result, some of y projects loading times are 5-10 times what they could be.

@MkeC
Yes, Blender tries to be clever, and prevents you from opening an image twice. As you said, this means that even if the textures are different, they both point to the same location to grab the image from.

The only solution (at runtime) that I’m aware of is duplicating the objects (mesh/material/textures/logic all included), you can do that with LibLoad. (Not with LibNew). Of course it’s an extreme waste of memory but that’s all I can think off that would work on vanilla BGE.

OK thanks, everyone. For what it is worth I had already started using different seed images with each mesh as a work around along the lines of sdfgeoff’s first response. I was just hoping there might be a more efficient approach. If there were ever a fix I would prefer to be able to dynamically manipulate texture slots linked to a material runtime rather than the images (or sources) linked to the textures slots but that is just my vote.