Earning pc.Entity member from pc.GraphNode


#1

Hello people! I’m new to PlayCanvas and javascript.

I’m struggling to access a script from child entity.

var nodes = this.entity.children;
for(i = 0; i < nodes.length; ++i)
  var node = nodes[i];

on this code, I expected node would be an Entity, so I tried to use node.script. but it wasn’t work.
later I found the node type was actually GraphNode. and Entity inherited GraphNode.
so my question is,
isn’t there any way to cast GraphNode to Entity like dynamic_cast on C++?
or can I get script form GraphNode object?

sorry for my bad English.


#2

Hi,

You can check if a node is an entity like so

if (node instanceof pc.Entity) {...}