Child Issues after Instantiate template Second time

Hi,

I am facing an issue where I cannot access the children of the entity within the template the second time. It works fine the first time, but after the level is destroyed and reinstantiated following cutscene1level1fail, the children are empty. Screenshot attached.

Hi @usama_jalal!

I’m afraid this isn’t enough information to find the cause.

Can you share your code or project maybe?

Hi @usama_jalal!

One thing you might want to check is the children of the reinstantiated entities. I’ve found that sometimes when working with template that the engine will attach an empty child entity as the first child, which may be what you’re running into. If this is the case, you’ll just want to check that the entity you’re searching for children for indeed has children, or make a direct reference to them in a script component.

I hope this is helpful!

If this is true then this is a very dangerous bug! :scream:

I’ll see if I can get it to reproduce on a new project. I just thought it was a quirk of the system and did a workaround, to just move onto the next child in the array if it wasn’t what I was looking for. Usually there was only one intended child, so it was easy.

1 Like

What you mentioned might be the case for the model component, which has an internal hierarchy of GraphNodes. Not a bug.

1 Like

In my case specifically, I found this issue with element components on a completely 2D project.

I suspect that’s the same thing, under the hood a model component is used.
Related ticket: Engine generated graph nodes in entities (eg elements) causing issues with children length · Issue #4333 · playcanvas/engine · GitHub

1 Like

I often use children[0] and children[1] to toggle between two entities. Currently I only do this with templates that already exist in the editor, but then this will fail when I use an instantiated template.

That makes a lot of sense. Thank you for clarifying!