Array of entities with specific script

How do I get an array of all entities in the scene with a specific script?

In my world it would be something like:


this.pNodes = [];
this.pNodes =this.app.root.findComponents("script").pNodeScript;

…but apparently this is nonsense. So how can I do it?

P.S I know I could get an array off ALL the objects in the scene with scripts and then filter through each of them but that seem very drawn out.

How about manually give every entity with that script a tag, then findbytag.

This code will get all the entities with the script “scriptName” and save it to this.pNodes.

this.pNodes = [];

this.pNodes = this.app.root.findScripts("scriptName");

for(i=0; i<this.pNodes.length; i++) {
    this.pNodes[i] = this.pNodes[i].entity;
}
1 Like