I tried to change the texture of an object in the blender game engine. I thought it would be a good idea to use the Texture Replacement from the Video Texture (bge.texture). I tried to run the following script:
def createTexture(cont):
obj = cont.owner
# get the reference pointer (ID) of the internal texture
ID = texture.materialID(obj, 'Kraftwerk2.png')
# create a texture object
object_texture = texture.Texture(obj, ID)
# create a new source with an external image
url = logic.expandPath(new_file)
new_source = texture.ImageFFmpeg(url)
# the texture has to be stored in a permanent Python object
logic.texture = object_texture
# update/replace the texture
logic.texture.source = new_source
logic.texture.refresh(False)
def removeTexture(cont):
"""Delete the Dynamic Texture, reversing back the final to its original state."""
try:
del logic.texture
except Exception as e:
print(e)
but it failed with the following error message:
Python script error - object 'Plane', controller 'Python': Traceback (most recent call last): File "F:\Benutzer\Merlin\MW-Industries\Blender Dateien\Cinema\Render-Blend\MoonSpace.ble nd\Test.py", line 19, in createTexture AttributeError: 'VideoTexture.Texture' object has no attribute 'materialID'
Is there a way to solve the problem?