Json errors when using ecs.GltfModel.set()?

Hi!

I am trying to spawn in instances of a glb. My code worked fine with spheres, but now when trying to replace those with a GLB instead, there seems to be some errors loading the GLTF Model?

I get this error

Unhandled promise rejection: SyntaxError: Unexpected token '<', "<?xml vers"... is not valid json

with this code

      ecs.GltfModel.set(world, entity, {
        url: './assets/Moss01A.glb',
      })

it says the error is at GLTFLoader.parse runtime.js

Is this because I cannot use a direct path and need a URL? How can I use a path?

Try renaming the file to collectableSpawner.js and wrapping the relative path with a require() statement:

ecs.GltfModel.set(world, entity, {
  url: require('./assets/Moss01A.glb'),
})

Found a solution!

Adding // @asset to the schema inputs (above) and then in the dropdown for that value on the component, choosing the model I want, rather than URL

2 Likes

Nice, this is the best practice! Thanks for sharing your solution!

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