STUDIO: apply texture at runtime

Hi there,

Sorry for the really basic question but I’m trying to apply a texture to a sphere entity at runtime. There seem to be no errors with the code but when testing, all I get is a black texture. My current code is:

  // Add material
  ecs.Material.set(world, sphereEntity, {
    r: 255,
    g: 255,
    b: 255,
    textureSrc: './assets/ballTexture1.png',
    roughness: 0.5,
    metalness: 0.5,
  })

Thank you in advance

Hi!

Wrap your reference inside of a require and it should work. Here’s an example:

ecs.Material.set(world, ent, {
  textureSrc: require('./assets/texture_01.png'),
  r: 255,
  g: 255,
  b: 255,
})
2 Likes

Hi George - Unfortunately I have this error

It should still work. However, changing your component file extension from .ts to .js should resolve the error.

1 Like

success! Thank you mate

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.