Skip to content

Commit dbf4e53

Browse files
authored
[FIX] Notify existing element descendants when a screen is added (playcanvas#8252)
1 parent cdceba5 commit dbf4e53

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/framework/components/screen/system.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,29 @@ class ScreenComponentSystem extends ComponentSystem {
6868
component.referenceResolution = component._referenceResolution;
6969
}
7070

71+
// Update any existing element components in the hierarchy that don't have a screen yet.
72+
// This handles cases where element components were added before the screen component.
73+
this._updateDescendantElements(component.entity, component.entity);
74+
7175
// queue up a draw order sync
7276
component.syncDrawOrder();
7377
super.initializeComponentData(component, data, _schema);
7478
}
7579

80+
_updateDescendantElements(entity, screenEntity) {
81+
const children = entity.children;
82+
for (let i = 0; i < children.length; i++) {
83+
const child = children[i];
84+
if (child.element && !child.element.screen) {
85+
child.element._updateScreen(screenEntity);
86+
}
87+
// Continue traversing unless this child has its own screen component
88+
if (!child.screen) {
89+
this._updateDescendantElements(child, screenEntity);
90+
}
91+
}
92+
}
93+
7694
destroy() {
7795
super.destroy();
7896

0 commit comments

Comments
 (0)