How to change the material (texture) in the BGE?

Example: A character is using defaut material, but I want after he has lost half his life, change his material to one with blood, with dirt, or if he is causing the character to change color like the Hulk, like me would you do to switch textures? Thank you for your time, God bless you s2!

material is mesh data. changing material on one instance changes it for all users of that mesh.
so the clean way to do this is copying the mesh, assign new material, replace mesh with copy.
forget doing that at runtime if youre not on upbge. even then, its not worth it.

so whats the alternative? replaceMesh
basic, shift-d duplicate mesh, assign new material, swap them out at runtime.
you can do it with the actuator too. its the same.


Do you really want to change the material or would changing just the texture be sufficient?

yes, enough

@Dan_Oliveira easy way is a driver using object color node

object color -> seperate RGB = gives you 3 uniforms to drive a node graph with

c = own.color
c[0] = own['Health']/own['MaxHealth']

own.color = c
1 Like