Engine - pc.app.root.findByName question

Hello. I have a quick question about engine.

generally I search entity by entity name with findByName method.

Somehow it returns GraphNode instead of Entity. Only findbyGuid returns Entity.

Also, I couldn’t find any property or method set guid manually.

Please let me know the way to get entity by name.

Thanks.

Hi @sooyong_Kim,

The pc.Entity class inherits from the pc.GraphNode class. FindByName will indeed return instances of both classes.

You can use the more generic find() and fineOne() methods to do what you are looking:

const entity = pc.app.root.findOne(o => {
   return o instanceof pc.Entity && o.name === 'Name to look for';
});

You can’t really set the GUID manually, that is generated in engine and it’s a private property. You could override it if you definitely need to do this, though I am afraid that can potentially break some things.

1 Like