关于多个Label导致DrawCall过高的问题

多个Label产生DC过多问题

这样写的代码:

@ccclass('TestComp')
export class TestComp extends Component {
    start(): void {
        for (let i = 0; i < 1000; i++) {
            let labelObj = new Node();
            let label = labelObj.addComponent(Label);
            
            label.string = i.toString();
            label.cacheMode = Label.CacheMode.CHAR;
            label.color = new Color(0, 255, 0, 125);
            labelObj.name = `label_${i}`;
            labelObj.scale = new Vec3(Math.random() * 2 + 1, Math.random() * 2 + 1, 1);
            
            labelObj.setParent(this.node);
            let randomPos = new Vec3(Math.random() * 1000 - 500, Math.random() * 1000 - 500, 0);
            labelObj.setPosition(randomPos);
        }
    }
}

产生的DC:4个,(其中1个是Profile)

但当把根节点的active置成false后再改成true,DC也会变到1001.

这样写的代码:

@ccclass('TestComp')
export class TestComp extends Component {
    start(): void {
        for (let i = 0; i < 1000; i++) {
            let labelObj = new Node();
            let label = labelObj.addComponent(Label);
            
            labelObj.setParent(this.node);
            let randomPos = new Vec3(Math.random() * 1000 - 500, Math.random() * 1000 - 500, 0);
            labelObj.setPosition(randomPos);
            
            label.string = i.toString();
            label.cacheMode = Label.CacheMode.CHAR;
            label.color = new Color(0, 255, 0, 125);
            labelObj.name = `label_${i}`;
            labelObj.scale = new Vec3(Math.random() * 2 + 1, Math.random() * 2 + 1, 1);
        }
    }
}

产生的DC:1001个,(其中1个是Profile)


  1. 为啥setParent的先后写的顺序,会影响DC。
  2. 为啥最开始4个DC,根节点active改成false又改成true后,DC也会变到1001.

求大佬解答

label.cacheMode = Label.CacheMode.CHAR;

看起来,缓存模式设置晚了

我试了下,还真是这样。不过为啥设置cacheMode放到setParent的前后,会有这么大影响。渲染相关的处理,难道不是在某个生命周期里去执行

如果合批缓存足够情况下,

还有dc增加的问题,估计是被改材质了

下面是别人遇到:

2赞