@elmeunick9: please stop telling people they can solve there issues with the bge by using another game engine. You can post that in the forums of that engine. This is the BGE support subforum. If you can’t help with the bge then you can just say it. Imagine how this forum looks like when all the other game engines are mentioned. It is not helpful.
@blendercomp: The error message and the function your code calls is pretty descriptive:
bge.texture.materialID(object, name)
Returns a numeric value that can be used in Texture to create a dynamic texture.
The value corresponds to an internal material number that uses the texture identified by name. name is a string representing a texture name with IM prefix if you want to identify the texture directly. This method works for basic tex face and for material, provided the material has a texture channel using that particular texture in first position of the texture stack. name can also have MA prefix if you want to identify the texture by material. In that case the material must have a texture channel in first position.
If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception.
Ex: bge.texture.materialID(obj, ‘IMvideo.png’)
Parameters:
object (KX_GameObject) – The game object that uses the texture you want to make dynamic.
name (str) – Name of the texture/material you want to make dynamic.
Returns:
The internal material number.
Return type: int
name is a material name - or a texture name. As you do not have a material or a texture with the name “moon000.png” the BGE will complain with:
RuntimeError: VideoTexture.materialID(ob, string): Object doesn't have material with given name
telling you exactly that.
[Side note: in the past it took me a while to distinguish the error message with what I expected to read. The error messages are usually pretty helpful]
Looking in your file: The object Plane has a material called “material” and a texture called “texture”. This means the BGE is absolutely correct, but it would be better if it shows the name that was searched for.
The BGE documentation is not really precise and the implementation does not match the one structure of Blender (e.g. Blender -> one material many textures, BGE - one mesh many textures matching the same number of materials). Additionally the above function uses “pre-2.49” methods to provide parameters. That is why you need the prefix “MA” and “IM”. Two functions would be more appropriate.
Anyway:
- your biggest issue is that you try to change the material of the camera (obj). Cameras have no materials
- I assume you want to change the material of object “Plane”. This requires either “MAMaterial” or “IMmoon_rotation.avi”.
My investigation show that the image of the first materials first texture is accessible only even when there are multiple images and multiple materials.
Remarks:
It is better to use objects with a single material and a single texture when it comes to video texture. Then you can assume materialID = 0.
The BGE API is very confusing
- it does not match the structure of what Blender uses (Object 1:1 Mesh 1:n Material 1:n Texture 1:1 image)
- it uses name prefixes to identify a material (pre-2.49 methods)
- the documentation talks about texture name, but the implementation uses image names (therefore “IM” prefix)
(pls. do not confuse image name with image file name).
I hope this helps a bit.