Skip to content

Instantly share code, notes, and snippets.

@elkraneo
Last active December 10, 2024 14:18
Show Gist options
  • Save elkraneo/cfdc40576bfdbdf419ea5acb86bbc4ac to your computer and use it in GitHub Desktop.
Save elkraneo/cfdc40576bfdbdf419ea5acb86bbc4ac to your computer and use it in GitHub Desktop.

Async loading equipment

FB16078151

The requirements for game equipment loading during setup, which we were unable to find any prior references for, took us off guard as I tried to control the loading flow. Using await "Entity(named" instead of the synchronous version leads to a silent failure that doesn't display the equipment ultimately. We found a reference on the forums involving using placeholder entities and recalculating the bounding box, but I'm not sure if this is the correct technique to asynchronously load entity equipment and feed it back into the system.

if let focusGreenEntity = try? await Entity(named: BundleAssets.focusGreenEntity, in: realityKitContentBundle) {
  if let equipment = game?.setup.colorEquipment.first(where: { $0.id == .FocusBlend.greenID }) {
    equipment.entity.addChild(focusGreenEntity)
    let bbox = focusGreenEntity.visualBounds(relativeTo: equipment.entity)
    game?.tabletopGame.addAction(.updateEquipment(equipment, boundingBox: Rect3D(bbox)))
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment