Strange behaviour of instantiate

Hello,

I’m on cocos creator 3.2.0.
I found a rather strange issue with the instantiate method.

I get this error when I instantiate a simple Custom collectible class which extends Node that has a sprite component added to it.
image

export class Collectible extends Node {
  private image: Sprite;

  constructor(spriteFrame: SpriteFrame, name: string | undefined = 'collectible') {
    super(name);

    this.image = this.addComponent(SpriteComponent);
    this.image.spriteFrame = spriteFrame;

    this.changeColor('#000000');
  }

  changeColor(color: string): void {
    this.image.color = new Color().fromHEX(color);
  }
}

I new this class and store it in a variable which I later instantiate to create a clone of it.
I then add this cloned collectible class to another node, which is where I’m encountering the problem.
image

image

Instead of instantiating if I were to new the class before adding it as a child it works fine.

It works fine when I use the instantiate method on classes that don’t have a sprite (renderable) component on the root node, but rather have child nodes which hold the sprite component.

Please Let me know what’s going wrong
I would immensely appreciate that

1 Like

I can ask engineering to take a look.

1 Like

Hello, according to your description, I made a demo, but failed to reproduce your problem on it. You can look at the demo and then modify the demo so that it can reproduce the problem.

@zzf_Cocos. @slackmoehrle

I have attached the demo project below with the above issue.
Have a look and please let me know what’s going on.
I assume it’s something to do with the cloning.

instantiate-check.zip (1.3 MB)

@zzf_Cocos , @slackmoehrle

Did you get a chance to look into this?
Do let me know. Thanks

I am asking engineering for their follow-up reply.

You need to modify the engine code to turn off this warning.
Here is the code you need to change:
图片

The reference path for this script is.

D:\CocosDashboard_1.0.10\resources\.editors\Creator\3.2.0\resources\resources\3d\engine\cocos\core\scene-graph\node-ui-properties.ts

Open the engine source code directory from here.
图片

After modification, the compilation engine:
20211227001

Waiting for compilation to complete

@zzf_Cocos, thanks for the solution
Will this issue be fixed in the future versions?

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.