Hi all, I'm trying to retrieve the name of an entity from the gesture that hits it, but it's not giving me the value I set when I created the entity.
I create the entity like:
class DrumPad: ObservableObject {
static func create(for audioFileName: String) -> Entity? {
do {
let padEntity = try Entity.load(named: "Geometry/pad-without-handle", in: tableDrummerContentBundle)
padEntity.name = "\(audioFileName)_pad"
return padEntity
} catch {
print("Could not load pad \(audioFileName)")
print(error.localizedDescription)
return nil
}
}
}
Then I get it from the gesture:
var body: some View {
RealityView { content in
for sampleName in audioSamples {
guard let pad = DrumPad.create(for: sampleName) else { continue }
content.add(pad)
}
}
.gesture(SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { value in
print(value.entity.name)
})
}
}
In the gesture handler, print(value.entity.name)
gives me the name of the root transform of the entity, PadTransform
, not the string I set "\(audioFileName)_pad"
during instantiation. If I call print(padEntity.name)
during instantiation, I get rock-kick-2_pad
and the like. Any help would be much appreciated.