Getting child from tag

Hello, I have a, I think, simple issue. I’m trying to get a childNode by using it’s tag. I have a function that is called several times:

    if(!this.hasPath) return;
    
    if(this.positionOnPath==1){

        var drawPrefab = cc.instantiate(this.drawPathNode);
        drawPrefab.getComponent('scr_drawPath').setPath(this.pathToTarget);
        drawPrefab.getComponent('scr_drawPath').draw(this.positionOnPath);
        this.node.addChild(drawPrefab,111);
        return;
    }

    var drawPrefab = this.node.getChildByTag(111);
    drawPrefab.getComponent('scr_drawPath').draw(this.positionOnPath);

As you can see, I create a childNode when the function is called and the ‘positionOnPath’ variable is set to ‘1’. The position get incremented elsewhere then the function is called again. I am wanting something different to happen when the position is not ‘1’ and I’m trying to update the childNode I created previously but I am unable to reference it. This is why I’m trying to use the getChildByTag feature.

Is there something obvious that I am doing wrong here?

Thanks in advance!
Sam

Nvm. I was able to change the code,

drawPrefab.setTag(111);
this.node.addChild(drawPrefab);

And that worked.

if you want to set a tag while adding the child in the same function it would be

this.node.addChild(drawPrefab,1, 111);

1 is the z-order and 111 is the tag.

Oh, okay. That makes sense. Cool. Thanks!