GraphNode as first child? Why?

It’s happening sometimes that when I iterate on the children of an entity, the first one is not an entity (as expected) but a pc.GraphNode.
This is often causing me issues as I can’t access the children by index. I have to loop to check if the child is an instance of pc.Entity. Or I cannot just use the length of the children to check how many entities I have.
Do you know why? And mainly, can this be avoided?
@vaios I suspect this is a subject for you :slight_smile:

1 Like

Various components like model components, element components and others need one or more internal graph nodes which are children of the Entity in order to function. There’s no ‘easy’ fix for this, if you need to check for Entities only I suggest you keep checking if the child is an instanceof pc.Entity.

Thanks for the explanation.
Unfortunately, it’s quite bad that it’s like this. I hope one day you can review/fix it.

Maybe this suggestion from @will could be the way to go:

This suggestion is not really going to fix this as the only thing that’d change in this case is that even those internal graph nodes would now be entities.

Technically these internal graph nodes are still valid children of the Entity. If you only want to access children that you have in the Editor then I think you kinda have to filter those children yourself… It’d make the engine pretty complicated to start separating children into different categories and especially if we get rid of graph nodes at some point that’s gonna make it even harder.

1 Like