3.0 Label调用updateRenderData不生效

3.0版本在给label动态设置string之后调用updateRenderData()方法,无法立即获取到新的label宽度

@ccclass('LabelTestManager')
export class LabelTestManager extends Component {
    @property(Label)
    contentLabel!: Label;

    start () {
        console.log(`length before: ${this.contentLabel.getComponent(UITransform)?.width}`);
        this.contentLabel.string = 'hello world'; 
        this.contentLabel.updateRenderData(true);
        console.log(`length after: ${this.contentLabel.getComponent(UITransform)?.width}`);
        this.scheduleOnce(() => {
            console.log(`length in next frame: ${this.contentLabel.getComponent(UITransform)?.width}`)
        });
    }
}

结果:
image

这是修复pr,合并下试试:
https://github.com/cocos-creator/engine/pull/8316/

label.enabled = false;
label.enabled = true;
这样它的宽高不就更新了吗?

start () {
        console.log(`length before: ${this.contentLabel.getComponent(UITransform)?.width}`)
        this.contentLabel.string = 'hello world'; 
        this.contentLabel.enabled = false;
        this.contentLabel.enabled = true;
        console.log(`length after: ${this.contentLabel.getComponent(UITransform)?.width}`)
        this.scheduleOnce(() => {
            console.log(`length in next frame: ${this.contentLabel.getComponent(UITransform)?.width}`)
        });
    }

image

目测没有更新

而且其实看源码:

public onEnable () {
        super.onEnable();

        // TODO: Hack for barbarians
        if (!this._font && !this._isSystemFontUsed) {
            this.useSystemFont = true;
        }
        // Reapply default font family if necessary
        if (this._isSystemFontUsed && !this._fontFamily) {
            this.fontFamily = 'Arial';
        }

        this.updateRenderData(true);
    }

也是调的updateRenderData,所以问题应该还是在这个方法里面

我用2.4.4试的可以的,3.0不晓得了 可能不一样了,

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。