How to change apply videotexture to material of imported file?

Hi, after importing some glb files from blender, I need to change material of “tv” with a video texture. Mateiral name is tv_mat. Tried this:

var myMaterial2 = scene.getMaterialByName("tv_mat");
var videoTexture = new BABYLON.VideoTexture("video", ["oppo.mp4","oppo.webm"], scene, true, true);
myMaterial2.diffuseTexture =  videoTexture;

However I get a log stating: TypeError: myMaterial2 is null

Ho do I properly change material?

That means you don’t have a material with name “tv_mat” in your scene. You must first correct that. You can try getMaterialByID() in case it is the id of the material that is “tv_mat”.

Unfortunately I got same result. In babylon sandbox (https://sandbox.babylonjs.com/) I can definitely see a material with “tv_mat” name, so maybe model hasn’t yet finished loading? Is of, what function do I check for “is loaded”?

I think a PG will be easier to deal with, if you can (https://playground.babylonjs.com).

Here it is: https://www.babylonjs-playground.com/#T7T1PU#1

You must wait for the scene to be loaded before being able to access objects from this scene.

The easiest way is to put your code in the callback:

https://www.babylonjs-playground.com/#T7T1PU#3

Also, note that materials loaded from a gtlf / glb file are PBR materials, not standard materials, so you should use albedoColor and not diffuseColor.

Thank you very much, will fix some uvs in my model and should be good to go.