spriteFrame is null after assigned in extension

Hi Friends,
I am having a problem while creating an extension which the main function is to load a json file and create nodes and components loaded from the Json file.

I am able to load the json file and get the information from that to create a simple node. However, when I try to add Sprite component to that node, I run into a problem which is I am not able to load spriteFrame, and assign to that node.

First I tried to use path to located the image file, but I cannot find the correct path.

In order to use cc.assetManager.loadAny, I use this code to get UUID:

const bgUUID = await Editor.Message.request('asset-db', 'query-uuid', 'db://assets/resources/main.png');

after that I use these line of code to add spriteFrame into Sprite component:

cc.assetManager.loadAny(bgUUID, function (err, sprite_frame)
{ 
if (err) {
console.log(err);
return;
}
 nodeBG.getComponent(cc.Sprite).spriteFrame = sprite_frame;
})

When I run the extension, I got this bug: [Scene] Cannot read property ‘width’ of undefined

Do you guys know what I am missing in here? Or what I am doing wrong?
I am using cocos creator 3.7.

Thank you!


You need to load the spriteFrame.

1 Like

Thank you so much for the reply. Ya, I also find out yesterday.