A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(ui): keep hit testing from bypassing interaction membership
yhh39ccab14f73a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2db724d73..f2bd996cc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Scene-authored scroll views receive hover and wheel input.** Hit testing no longer inserts hidden interaction components outside the SDK's component index. The interaction system owns creation and query invalidation, so wheel scrolling and per-frame hover/press state work for controls placed in the editor.+- **Claimed input releases cannot leave gameplay controls held.** Keyboard, mouse and touch releases consumed by an editor or UI handler silently retire the previous held state without manufacturing gameplay release edges. UI capture receives primary-pointer cancellation instead of a click, even across frame-edge clearing; unowned touch moves and releases do not create ghost contacts.- **UI gesture bindings expire with their targets and App.** App cleanup unregisters only its own input handler and clears captures. Despawn removes gesture callbacks and pending markers through one shared World observer; a cancelled frame click no longer suppresses a later click after the control is re-enabled.diff --git a/sdk/tests/ui-nested-canvas-wasm.test.ts b/sdk/tests/ui-nested-canvas-wasm.test.tsindex a6ce88d0b..63e251719 100644--- a/sdk/tests/ui-nested-canvas-wasm.test.ts+++ b/sdk/tests/ui-nested-canvas-wasm.test.ts@@ -6,7 +6,7 @@ import { Canvas, Camera, SceneOwner, Transform } from '../src/ecs/component';import { collectCameras } from '../src/camera/CameraPlugin';import { UINode, UIPositionType } from '../src/ui/core/ui-node';import { UIVisual } from '../src/ui/core/ui-visual';-import { Interactable } from '../src/ui/input/interactable';+import { Interactable, UIInteraction } from '../src/ui/input/interactable';import { px } from '../src/ui/core/dimension';import type { CppRegistry, ESEngineModule } from '../src/wasm';import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';@@ -59,8 +59,12 @@ describe.skipIf(!HAS_WASM)('nested canvas layout and ordering on real WASM', ()expect([root, container, sibling].map(entity => engine.ui_getCullBit!(registry, entity))).toEqual([2,2,2]);expect([nested, leaf].map(entity => engine.ui_getCullBit!(registry, entity))).toEqual([8,8]);const point = world.get(leaf, Transform).worldPosition;+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([]);engine.uiHitTest_updateDomains!(registry, point.x, point.y, 100, 0, 0, -1,point.x, point.y, 100, 0, 0, -1);expect(engine.uiHitTest_getHitEntity()).toBe(leaf);+ expect([root, container, nested, leaf, sibling].some(entity => registry.hasUIInteraction(entity))).toBe(false);+ world.insert(leaf, UIInteraction, { hovered: true });+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([leaf]);});});diff --git a/sdk/tests/ui-pick-world.test.ts b/sdk/tests/ui-pick-world.test.tsindex 99a84166a..bf02f065e 100644--- a/sdk/tests/ui-pick-world.test.ts+++ b/sdk/tests/ui-pick-world.test.ts@@ -9,8 +9,14 @@*/import { describe, it, expect, beforeAll } from 'vitest';import { World } from '../src/ecs/world';+import { App, flushPendingRegistrations } from '../src/app/app';+import { AppContext, setDefaultContext } from '../src/ecs/context';+import { Input, InputState } from '../src/input/input';+import { UICameraInfo } from '../src/ui/core/ui-camera-info';+import { UILayoutGeneration } from '../src/ui/layout/ui-layout-generation';+import { uiInteractionPlugin } from '../src/ui/input/interaction';import { Transform, Sprite, MeshRenderer } from '../src/ecs/component';-import { Interactable } from '../src/ui/input/interactable';+import { Interactable, UIInteraction } from '../src/ui/input/interactable';import type { Entity, Vec3 } from '../src/types';import type { ESEngineModule, CppRegistry } from '../src/wasm';import { loadWasmModule, HAS_WASM } from './helpers/loadWasm';@@ -102,6 +108,18 @@ describe.skipIf(!HAS_WASM)('world-space picking (WASM integration)', () => {return module.uiHitTest_getHitEntity();}+ it('picking leaves interaction ownership and cached membership to the SDK', () => {+ const { world, registry } = createWorld();+ const e = sprite(world, 0, 0);+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([]);+ expect(pickAt(registry, 0, 0)).toBe(e);+ expect(registry.hasUIInteraction(e)).toBe(false);+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([]);+ world.insert(e, UIInteraction, { hovered: true });+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([e]);+ disposeWorld(world, registry);+ });+it('hits a sprite that has no UINode', () => {const { world, registry } = createWorld();const e = sprite(world, 0, 0);@@ -122,18 +140,30 @@ describe.skipIf(!HAS_WASM)('world-space picking (WASM integration)', () => {disposeWorld(world, registry);});- it('sets UIInteraction, which is what the drag system gates on', () => {- const { world, registry } = createWorld();+ it('the interaction system publishes hover membership and clears it after moving away', async () => {+ setDefaultContext(new AppContext());+ const registry = new module.Registry();+ const app = App.new(); app.connectCpp(registry, module);+ const world = app.world;const e = sprite(world, 0, 0);-- pickAt(registry, 0, 0);-- // The engine writes it, so ask the engine: this is the component the drag- // system reads `hovered` from, and nothing else creates it here.- const reg = registry as unknown as { hasUIInteraction(e: number): boolean };- expect(reg.hasUIInteraction(e)).toBe(true);-- disposeWorld(world, registry);+ const input = new InputState(); input.mouseX = 50; input.mouseY = 50;+ app.insertResource(Input, input);+ const projection = new Float32Array([.02,0,0,0, 0,.02,0,0, 0,0,-.001,0, 0,0,0,1]);+ app.insertResource(UICameraInfo, { ...UICameraInfo._default, viewProjection: projection,+ vpW: 100, vpH: 100, screenW: 100, screenH: 100, valid: true });+ app.insertResource(UILayoutGeneration, { generation: 0 });+ uiInteractionPlugin.build(app); flushPendingRegistrations(app);+ try {+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([]);+ world.ensureTransformsComposed();+ await app.tick(1 / 60);+ expect(world.getEntitiesWithComponents([UIInteraction])).toEqual([e]);+ expect(world.get(e, UIInteraction).hovered).toBe(true);+ input.mouseX = 500; await app.tick(1 / 60);+ expect(world.get(e, UIInteraction).hovered).toBe(false);+ } finally {+ uiInteractionPlugin.cleanup(app); disposeWorld(world, registry);+ }});it('honours raycastTarget: false', () => {diff --git a/src/esengine/ui/UISystem.cpp b/src/esengine/ui/UISystem.cppindex c25d38c4e..a1d93da3b 100644--- a/src/esengine/ui/UISystem.cpp+++ b/src/esengine/ui/UISystem.cpp@@ -12,7 +12,6 @@#include "../ecs/components/Interactable.hpp"#include "../ecs/components/Transform.hpp"-#include "../ecs/components/UIInteraction.hpp"#include "../ecs/components/UINode.hpp"#include "../ecs/components/UIVisual.hpp"#include "../ecs/components/Sprite.hpp"@@ -49,8 +48,6 @@ void UISystem::hitTestUpdate(Registry& registry, const PickRay& worldRay, const// clickable and what is visible cannot come apart.const PickRay& ray = screen_domain_.count(entity.id()) != 0 ? screenRay : worldRay;- registry.getOrEmplace<UIInteraction>(entity);-auto& t = registry.get<Transform>(entity);t.ensureDecomposed();@@ -176,7 +173,6 @@ void UISystem::hitWorldContent(Registry& registry, const PickRay& ray,});if (!haveBest) return;- registry.getOrEmplace<UIInteraction>(best);hitResult.hit_entity = best;}diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex bf6dbc099..eedef1e5d 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(ui): keep hit testing from bypassing interaction membership':+ { note: 'Scene-authored scroll views receive hover and wheel input.' },'fix(input): retire held state when release events are consumed':{ note: 'Claimed input releases cannot leave gameplay controls held.' },'fix(ui): release gesture bindings and expire cancelled click markers':