按照官方文档的操作,在 Cocos 3.8.6 里执行:
import { _decorator, Component, MeshRenderer, Sprite } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('EntryComp')
export class EntryComp extends Component {
start() {
const nodeB = this.node.getChildByName('SpriteB');
const rendererB = nodeB.getComponent(MeshRenderer);
console.log('rendererB:', rendererB); // null
}
}
此时浏览器会报错 getComponent: Type must be non-nil,且 MeshRenderer 获取为 null(导致无法调用 MeshRenderer 的 setInstancedAttribute 方法):
另外节点也无法添加 MeshRenderer 组件,只有一个叫 UIMeshRenderer 的组件:
这个组件已废弃,且该组件的接口里也不存在 setInstancedAttribute 方法。
有了解的大佬么?

