VideoTexture RunTime Error: "Object doesn't have material with given name"

greets fellow blenderheads,
I have been trying to play a video in BGE following the info on this man page:

without much success. I get the following error:


Python script error - object 'Camera', controller 'Python':
Traceback (most recent call last):
  File "LoadVideo.py", line 10, in <module>
RuntimeError: VideoTexture.materialID(ob, string): Object doesn't have material with given name
Blender Game Engine Finished

See attached file.
Interestingly enough, a texture named ‘moon000.png’ and a video named ‘moon_rotation.ogv’ reside in the same dir as the blend file.

What am I missing?
Thanx in advance

Attachments

BGE_videoTexture_sample.blend (585 KB)

@blendercomp

Your screen object must have a material wich in turn needs a image texture (that you will replace with the video) in it. Or if you were using upbge’s community addon you would just do “media.Screen(myobject).play(“myvideo.mp4”)” and it would work automagically (and with audio) even if the object in question doesn’t have a material or texture in it.

EDIT: Uhh I didn’t look at the .blend, seems you already have the material. Here is what you did wrong (again, using UPBGE’s Community Addon is so much easier, you should try it).

  • You have 2 scripts, from “load” you call “update”, but you don’t import “update” so there is no way python finds it. And actually, you make the videotexture update call in your “load”, meaning that it was clearly designed to be called each frame. In short, delete the Update script and its call.
  • Your material is not shadeless, even if everything were working you wouldn’t see it since you don’t have any light in the scene. And you don’t need to set you texture source as “video”, you also should try packing it.
  • You’re using the worng object, you want to use “Plane” and instead you’re using “Camera”.
  • Some other python errors.

Heck, I every time I look at this code I realize why I did the Video Component, it’s not right even in the documentation. You should not use “logic.video” to store your video, it’s nonsense, you should use your screen object.

Blend: BGE_videoTexture_sample.blend (592 KB)

P.S. You can do this with UPBGE’s Community Addon in 20s and without a single line of code for the video. (You need about 3 lines though to make Shia transparent).

EDIT2: Ahh and I forgot to mention that you must controll the framerate manually, otherwise you’ll be refreshing your video at 60fps (usually you only need 25fps) wich will slow down your whole game. Again UPBGE’s Community Addon does this for you in the shadows.

@elmeunick9
thank you for your elaborate explanation. I liked the heads up regarding frame rate update.

The addon looks cool, didn’t know about it.
I will most certainly be checking it out - especially if it allows proper video playback.

@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.

I don’t think there is anything wrong promoting UPBGE here, it is, after all, not another game engine. And furthermore, I was giving help for the BGE. Almost every part of my previous post is about BGE so I don’t know what you’re talking about. Monster, what are you afraid of? UPBGE taking the forum? Even if that were to happen it will still be “The BGE” sub-forum, since they are both pretty much the same.


Call me blind, but I don’t see the diference.

not to start an argument here, but that screenshot is very misleading. its technically not even of the UPBGE/BGE at all. that is the blender render. but if you switched it to the game mode, then there would be several big differences, especially in the world tab. the UPBGE also has a different python api, and many features that the normal bge doesnt have.

while i dont think monster is afraid of the UPBGE “Taking Over”, its more a matter of clarity. if the original post is about the BGE, then the answers should be about the BGE. imagine how confusing it would be if half the answers are for the UPBGE, and half for the BGE. definitely not good. but i also dont see a problem with suggesting the UPBGE as an alternative, especially if the answer can only be done in the UPBGE. simple answers are the best answers.

plus, i see the UPBGE as a platform for the performance enthusiasts and more skilled game devs. just as many prefer the BI over Cycles, the vanilla BGE is good for beginners, or those like me, who can do without the million extra options to mess with.

and since when did this become a competition anyhow?

Upbge is another game engine, it is definitively not the same. I do not see referring another engine as alternative to a provided BGE solution. As this is the BGE forum this should be limited to a minimum.

Too late. We should probably discuss this on a new thread if we don’t want to go offtopic.

, but that screenshot is very misleading. its technically not even of the UPBGE/BGE at all. that is the blender render.

Technically that is what you have after starting Blender and UPBGE executables, exactly the same. That would not happen if it were another game engine. Do you realize how riduclus would be that argument if I were to compare BGE and Unity?

plus, i see the UPBGE as a platform for the performance enthusiasts and more skilled game devs. just as many prefer the BI over Cycles, the vanilla BGE is good for beginners, or those like me, who can do without the million extra options to mess with.

UPBGE should be the standard defacto, it has the same features than normal BGE (meaning that is not harder to use) plus more.

Unity is another game engine, Godot is another game engine, not UPBGE. If you put UPBGE on the category of a diferent game engine becouse of the diferences on the API&Features, you need to put Blender 2.4x there as as well, otherwise you’re not making any sense. But again, 2.4x is not banned in this forum, no reason to bann UPBGE, that would be plain discrimination.

In most cases, this included, the solution is exactly the same in both versions of the engine. Exactly the same. If you think the alternative I provided was to “use UPBGE”, you’re completly wrong and you need to read that post again.

My alternative method is using an Addon, and addon that, by the way, is compatible with BGE as well (though I don’t give support for that option).

P.S There is no forum for UPBGE and you know it, so stop sending UPBGE users to dev/null.

You already know this thread belongs to the BGE. Upbge is irrelevant. Mentioning it is confusing and not helpful. Promoting an upbge add-on is even more distracting.

That makes no sense. Upbge and BGE are different engines and evolve into different directions.

This is no argument to hijack BGE threads. This is a BGE thread.

Whoa! Didn’t realize that an addon could be such a highly contested political issue :0

@Monster: thank you for your elaborate explanation of the error message.
Bumped into this treasure while googling a solution:

http://www.tutorialsforblender3d.com/Game_Engine/VideoTexture/VideoTexture_Movie_5.html
There’s a blend file which works out of the box! Kudos to the site maintainer (Clark Thames) for setting up and sharing the file which works with v. 2.7+

Don’t really know how updated the API is but I find it to be confusing. Maybe it’s just me.