# Cant change material on GLB via code

**URL:** <https://forum.8thwall.com/t/cant-change-material-on-glb-via-code/5859>\
**Category:** Technical Support\
**Tags:** general, studio\
**Created:** [April 2, 2025, 5:16am UTC](https://forum.8thwall.com/t/cant-change-material-on-glb-via-code/5859 "2025-04-02T05:16:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_King](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sebastian\_King](https://forum.8thwall.com/u/Sebastian_King)\
**Post date:** [April 2, 2025, 5:16am UTC](https://forum.8thwall.com/t/cant-change-material-on-glb-via-code/5859/1 "2025-04-02T05:16:08Z")

</div>

Hello, I’ve followed the animated material template’s method of applying animated materials to models in Niantic Studio. Unfortunately I haven’t had any success getting it working. The shader works fine when applied to a primitive, but the same is not true for a GLB. Does anyone happen to know what I’m doing wrong?

I’m just trying to tile a material, and using ecs.Material.set to set the offset property doesn’t work. When I change the offset on the material on the GLB, that reverts to 0. I’ve tried importing a GLB WITHOUT a material as well and there’s no difference in behaviour.

Cheers

> import \* as ecs from ‘[@8thwall](https://forum.8thwall.com/groups/8thwall)/ecs’
> 
> const {THREE} = window as any
> 
> let material = null
> 
> ecs.registerComponent({  
> name: ‘scrolling-texture’,  
> schema: {},  
> schemaDefaults: {},  
> data: {  
> time: ecs.f32,  
> },  
> add: (world, component) =\> {  
> ecs.Material.remove(world, component.eid)  
> const object = world.three.entityToObject.get(component.eid)
> 
> ```
> const texture = new THREE.TextureLoader().load(
> `${require('./assets/ballTexture1.png')}`,
> (tex) => {
> console.log('Texture loaded successfully:', tex)
> },
> undefined,
> (err) => {
> console.error('Error loading texture:', err)
> }
> )
> 
> texture.wrapS = THREE.RepeatWrapping
> texture.wrapT = THREE.RepeatWrapping
> 
> material = new THREE.ShaderMaterial({
> uniforms: {
> time: {value: 0},
> texture1: {value: texture},
> },
> vertexShader: `
> varying vec2 vUv;
> void main() {
> vUv = uv;
> gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
> }
> `,
> fragmentShader: `
> uniform float time;
> uniform sampler2D texture1;
> varying vec2 vUv;
> void main() {
> vec2 uv = vUv;
> uv.x += time * 0.1; // Scroll horizontally
> gl_FragColor = texture2D(texture1, uv);
> }
> `,
> })
> 
> object.material = material
> object.traverse((node) => {
> if (node.isMesh) {
> console.log('Applying material to mesh:', node.name || 'unnamed mesh')
> node.material = material
> }
> })
> 
> ```
> 
> },  
> tick: (world, component) =\> {  
> material.uniforms.time.value = world.time.elapsed \* 0.001  
> },  
> remove: (world, component) =\> {},  
> })

---

<div class="post-metadata">

**Author:** ![GeorgeButler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.8thwall.com/georgebutler/32/1903_2.png) [@GeorgeButler](https://forum.8thwall.com/u/GeorgeButler)\
**Post date:** [April 2, 2025, 4:40pm UTC](https://forum.8thwall.com/t/cant-change-material-on-glb-via-code/5859/2 "2025-04-02T16:40:12Z")

</div>

You need to wait for the model to be fully loaded before traversing it.

> **[General Events | 8th Wall](https://www.8thwall.com/docs/studio/api/events/general/#gltf_model_loaded)**
>
> Events
