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
name
assigned (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 seenTargets
is always emptyentity?.name
returnsundefined
, even thoughname
is set in Studioentity?.rotation
and other transform data are alsoundefined
, as if the component was never properly attached or activated
Things I’ve tried:
- Replacing
eid
withschema.trackedTarget
(no difference) - Adding another component to confirm image readiness — it prints logs correctly
- Listening to
xrimagefound
withdocument.addEventListener()
— butevent.detail.name
returns 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 (
xrimagefound
etc.) instead of ECS bindings?
Any insight or working examples would be greatly appreciated. Thank you for your help!