Add floor mesh with promise

I am a little lost on the use of async and await. I need to add my meshes to floormesh, usually like this:
defaultXRExperience.teleportation.addFloorMesh(this.scene.getMeshByName(“SM_TableFloor”) );

***But this doesn’t work within a promise like async CreateEnvironment(): Promise {

Specific error is:
TS2339: Property ‘teleportation’ does not exist on type ‘Promise’.
58 |
59 | // Add some floor tiles to the floorMesh for teleportation -R

60 | defaultXRExperience.teleportation.addFloorMesh(this.scene.getMeshByName(“SM_TableFloor”) );

Could you provide the full source code of how you initialize defaultXRExperience?

If it is using createDefaultXRExperienceAsync from the scene, you should do something like:

const defaultXRExperience = await scene.createDefaultXRExperienceAsync(...);
defaultXRExperience.teleportation.addFloorMesh(...);

My setup is like this:

async CreateEnvironment(): Promise<void> {
    const defaultXRExperience = this.scene.createDefaultXRExperienceAsync({ floorMeshes: []} );

    const { meshes } = await SceneLoader.ImportMeshAsync(
      "",
      "./models/",
      "FOV_set_v1.glb"
    );
    this.models = meshes;
    
   // Add some floor tiles to the floorMesh for teleportation -R
   defaultXRExperience.teleportation.addFloorMesh(this.scene.getMeshByName("SM_TableFloor") );

So you must add the await keyword before this.scene.createDefaultXRExperienceAsync.

1 Like