How to change texture on the fly ? (runtime)

Hello!

My warrior wears a blue armor by default.

What if I want to pick up a “golden armor” ?

I have seen a changeMesh command.

But would it be possible to just change the material of the mesh ? But this needs be done at runtime.

Thanks a lot !

In UPBGEthere is a python function called replaceMaterial(), but it isn’t available in vanilla BGE.
As far as I know, replacing textures is not supported so you have to change the material in order to change textures.

You can use 4 or more textures using a node material and object color…

or one could use object color to pass uv cords to a node material altas texture and get many more textures out of 1.

You can use a stencil (mask) texture for the parts that change color, make them white by default and multiply their color by your desired one. This could be done through nodes.

BGE:

  • replace mesh (includes Materials) - even works on rigged objects like cloth.

  • UV coordinates (via Python) - but is shared on all other instances of the same mesh (unless you create a separate copy via LibNew).

  • VideoTexture (via Python) - exchanges the texture (not the material) with a texture of different sources. Have a look at

  • Dynamic Texture - easy to use VideoTexture (2.68+)

Personally, I know two ways to change the texture (color):

  • in this thread(possible to use as a tutorial) - Monster about this above wrote.
  • or bake an AO, with scuffs and normal map, set in Texture / Blend - Multiply or Add, and change the main color of the material through the script
    Another option is possible, through the GLSL shader - I somehow experimented with the shaders from Martins Upitis (Cube Map), so everything changes on the fly. Alas, I do not even know how to write such a simple shader (simple texture). I still have the confidence that all this is possible and optimal. Unfortunately, Martins hard to connect to this. With such a question, then someone handed me my brains (T), and then everything died down.