Hi,
I’m currently building an AR experience using image targets with ECS components, and I’m running into an issue with retrieving target data.
What I’m trying to do:
I want to detect which image target has been recognized and retrieve its name (or a consistent identifier), so I can store it in a Set and later send the results to a LINE Bot.
What I’ve implemented:
- Each image target in Studio has a unique
nameassigned (e.g.,Bat,Dog, etc.) - I attached a custom component to each image target like this:
export const seenTargets = new Set<string>();
(globalThis as any).seenTargets = seenTargets;
ecs.registerComponent({
name: 'image_target_tracker',
stateMachine: ({ world, eid }) => {
ecs.defineState('default')
.initial()
.onEnter(() => {
const entity = world.getEntity?.(eid) ?? world.entity?.(eid);
const name = entity?.name;
if (name) {
seenTargets.add(name);
console.log('[tracker] detected:', name);
} else {
console.warn('[tracker] no name:', eid);
}
});
}
});
What’s not working:
- The
onEnter()state never appears to trigger when an image target is found seenTargetsis always emptyentity?.namereturnsundefined, even thoughnameis set in Studioentity?.rotationand other transform data are alsoundefined, as if the component was never properly attached or activated
Things I’ve tried:
- Replacing
eidwithschema.trackedTarget(no difference) - Adding another component to confirm image readiness — it prints logs correctly
- Listening to
xrimagefoundwithdocument.addEventListener()— butevent.detail.namereturns empty or no event is triggered
My questions:
- What is the correct way to trigger a custom ECS component when an image target is recognized?
- Once a target is successfully detected, is there any way to access its physical tracking data, such as:
- 3D position (x/y/z)
- rotation or orientation
- transformation matrix or anchor info?
- Would it be more reliable to implement this via external event listeners (
xrimagefoundetc.) instead of ECS bindings?
Any insight or working examples would be greatly appreciated. Thank you for your help! ![]()