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.
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.
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