[SOLVED] findByTagName Error

Hello,
I am using trigger volume to enable and disable the elements.
following source code was working fine before a month ago.
But now its not working and displays following error.

[playcanvas.dbg.js?version=1.49.3:8377]: Uncaught TypeError: this._children[i].tags._has is not a function

Is there any changes?Please help me to solve me this issue. Thank you in advance.

Following is my source code.

var TriggerVolume = pc.createScript('triggerVolume');

TriggerVolume.attributes.add('tagname', {
    type: 'string'
});

TriggerVolume.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
    this.entity.collision.on('triggerleave' , this.onTriggerLeave, this);
};

TriggerVolume.prototype.onTriggerEnter = function() {
    var entityArray = this.app.root.findByTag(this.tagname);
    for(var i = 0; i < entityArray.length; ++i) {
        entityArray[i].enabled = true;
    }

};

TriggerVolume.prototype.onTriggerLeave = function() {
    var entityArray = this.app.root.findByTag(this.tagname);
    for(var i = 0; i < entityArray.length; ++i) {
        entityArray[i].enabled = false;
    }

};

Hi @Tom_Tom,

Code looks correct, not sure what the issue is. You can step in with the debugger by adding a breakpoint at your findByTag calls and what is not defined there.

Otherwise try sharing a sample project that reproduces the issue to take a look.

I am not aware of any change on that method in a long time.

1 Like

Seems to work fine in this example using your script as-is: https://playcanvas.com/editor/scene/1275106

2 Likes

Thank you very much for the fast response.

I found the source code working fine when I don’t connect to my socket address for Real Time Multiplayer.
As I connect to my Socket address it seems to be the problem.

I am using following version of socket for network connection.
/*! * Socket.IO v2.3.0

  • (c) 2014-2019 Guillermo Rauch
  • Released under the MIT License.
    */

It sounds like a project specific problem where there may be some code that accidentally changes the value/object of app.root. Socket alone wouldn’t/shouldn’t do that

Thank you very much for the help.
I found the reason for the error.
The code was all fine.
when I pass the user id to the Other players tags it shows me the error.
I managed to solve it out.