Skip to content

Commit

Permalink
Fix error when physicsMaterial used in prefab (#2519)
Browse files Browse the repository at this point in the history
* fix: error when physicsMaterial used in prefab
  • Loading branch information
luzhuang authored Jan 21, 2025
1 parent f8d508e commit 3aa4b82
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/loader/src/prefab/PrefabResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ export class PrefabResource extends ReferResource {
*/
_addDependenceAsset(resource: ReferResource) {
this._dependenceAssets.add(resource);
// @ts-ignore
resource._associationSuperResource(this);
// @todo: The PhysicsMaterial does not inherit from ReferResource. Currently,
// ReferResource requires the engine to be passed as a parameter, which prevents cross-engine reuse.
// A refactor of ReferResource will be needed in the future.
if (resource instanceof ReferResource) {
// @ts-ignore
resource._associationSuperResource(this);
}
}

protected override _onDestroy(): void {
super._onDestroy();
this._root.destroy();
this._dependenceAssets.forEach((asset) => {
// @ts-ignore
asset._disassociationSuperResource(this);
if (asset instanceof ReferResource) {
// @ts-ignore
asset._disassociationSuperResource(this);
}
});
}
}

0 comments on commit 3aa4b82

Please sign in to comment.