Replace the texture dynamically in BGE (Blender 2.65)


I want to adapt the second script given at to dynamically replace the textures of several objects. The execution of my script comes to replace last object processed but not others. In fact, after my various tests, I found that the refresh of the screen is at the end and so we can see the result on the last subject matter and the others remain unchanged!

I need your help please.

It would be helpful to see the code you’re trying to use. Otherwise, we’d just be guessing all day at potential problems.

Could you please provide a sample-blend-file of your problem?

I’ve played around with those texture-functions and haven’t had any problems except my own faults.

One point the example lacks: you need to save the new texture.
Something like:

own['RenderedTexture'] = texture.Texture(own, matID)
own['RenderedTexture'].source = texture.ImageRender(scene, camSrc)

Don’t (!) put them all at: logic.texture
like the sample says. Because with each new texture you put there, the old, already being there, texture will get deleted.
So save each new create texture you need to an own place. Like:

own[‘texture1’]= texture.Texture(own, matID1)
own[‘texture2’]= texture.Texture(own, matID2)
own[‘texture3’]= texture.Texture(own, matID3)

Hmm i was able to change textures in a little game i made using similar code (though only for one object at a time). Can you post your code? That will help us find where the problem is.
Also if all your objects are duplicates of each other you will be changing textures for all of them at once because they share the same material.

A thousand thank you really. it’s been almost a month since I turned this script in all directions. Thanks to you I understand what it does and my script runs fine now. I also remerci Moguri Anurag and me answering.

I take this opportunity to ask you a question: Is there a way to keep these changes without them disappear at the end of the execution of the game?

thank you very much