Loop through the entities/nodes

Hi,
I have self-hosted Playcanvas app. Part of the code for creating playcanvas app as follow :

      canvas = createCanvas();
      devices = createInputDevices(canvas);

  
          app = new pc.Application(canvas, {
              elementInput: devices.elementInput,
              keyboard: devices.keyboard,
              mouse: devices.mouse,
              gamepads: devices.gamepads,
              touch: devices.touch,
              graphicsDeviceOptions: window.CONTEXT_OPTIONS,
              assetPrefix: window.ASSET_PREFIX || "",
              scriptPrefix: window.SCRIPT_PREFIX || "",
              scriptsOrder: window.SCRIPTS || [ ]
          });

The scenes are loaded to the app with other script from json file.

How can I loop through all the entities (some boxs) in the app/scene, add “on click” event, change their color?
I want to also to show information when the user click on each box.

The photo below show what I get from console.log(this.app.root):
I am trying to acess graph node “3D” and it’s children shown with red border.

If I understood clear, there is some methods of Entity: find, findByName, et.c.

You have to use raycasting or framebuffer picking. This set of tutorials/project samples should help: https://developer.playcanvas.com/en/tutorials/?tags=raycast

Thank you guys for your help. What I was doing is to integrate Playcanvas inside Meteorjs application which uses React for front-end rendering. I made Playcanvas component that can speak with MongoDB database and exchange data with my Web application. The problem was that I was calling the findByTag command before it finishes loading thus nothing was returned. The problem is solved now.
The result of the App look as shown in the picture


When user interacts with the UI on the left the color of the balls change to reflect the overall satisfaction level.

1 Like