From e371204ba4025c0d4ccc93dc7d9ef055eb76c27c Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Dec 2024 15:39:14 +0800 Subject: [PATCH] Fix that the reparented items outside mask clip rect still could be touched. When reattaching the current node, the masks of all its descendants need to be recalculated since IMask caches the index which means the distance to Mask node. Reported at https://forum.cocos.org/t/topic/163455/238?u=dumganhar There are two relevant PR requests: ## 1. https://github.com/cocos/cocos-engine/pull/8313 This PR could not fix the issue totally, there is a currMask cache which will be used for all current node's descendants, but descendants's IMask may have different 'index' value which indicates the distance to the Mask node. public reattach (): void { let currMask; this.node.walk((node) => { if (!currMask) { currMask = _searchComponentsInParent(node as Node, NodeEventProcessor._comp); } ...... }); } ## 2. https://github.com/cocos/cocos-engine/pull/9363 This PR made _searchComponentsInParent as instance method but in 'reattach', it will always invoke '_searchComponentsInParent' for the current node. --- cocos/scene-graph/node-event-processor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index da4c3875535..5dae5eb9ec3 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -169,12 +169,11 @@ export class NodeEventProcessor { } public reattach (): void { - let currentMaskList: IMask[] | null; this.node.walk((node) => { - if (!currentMaskList) { - currentMaskList = this._searchComponentsInParent(NodeEventProcessor._maskComp); - } - node.eventProcessor.maskList = currentMaskList; + const eventProcessor = node.eventProcessor; + // NOTE: When reattaching the current node, the masks of all its descendants need to be recalculated + const currentMaskList = eventProcessor._searchComponentsInParent(NodeEventProcessor._maskComp); + eventProcessor.maskList = currentMaskList; }); }