# Child Issues after Instantiate template Second time

**URL:** <https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732>\
**Category:** Help & Support\
**Tags:** editor\
**Created:** [January 10, 2025, 6:11am UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732 "2025-01-10T06:11:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![usama\_jalal](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/usama_jalal/32/27197_2.png) [@usama\_jalal](https://forum.playcanvas.com/u/usama_jalal)\
**Post date:** [January 10, 2025, 6:11am UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/1 "2025-01-10T06:11:48Z")

</div>

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.

 ![image](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/4/3/4306a6e912419631336956adb47ec0766850b099.png)

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [January 10, 2025, 1:03pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/2 "2025-01-10T13:03:06Z")

</div>

Hi @usama_jalal!

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

Can you share your code or project maybe?

---

<div class="post-metadata">

**Author:** ![eproasim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/eproasim/32/22818_2.png) [@eproasim](https://forum.playcanvas.com/u/eproasim)\
**Post date:** [January 10, 2025, 3:50pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/3 "2025-01-10T15:50:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [January 10, 2025, 4:21pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/4 "2025-01-10T16:21:50Z")

</div>

> [@eproasim](#):
>
> I’ve found that sometimes when working with template that the engine will attach an empty child entity as the first child

If this is true then this is a very dangerous bug! 😱

---

<div class="post-metadata">

**Author:** ![eproasim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/eproasim/32/22818_2.png) [@eproasim](https://forum.playcanvas.com/u/eproasim)\
**Post date:** [January 10, 2025, 4:23pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/5 "2025-01-10T16:23:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [January 10, 2025, 4:32pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/6 "2025-01-10T16:32:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eproasim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/eproasim/32/22818_2.png) [@eproasim](https://forum.playcanvas.com/u/eproasim)\
**Post date:** [January 10, 2025, 4:37pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/7 "2025-01-10T16:37:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [January 10, 2025, 4:46pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/8 "2025-01-10T16:46:13Z")

</div>

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](https://github.com/playcanvas/engine/issues/4333)

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [January 10, 2025, 5:13pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/9 "2025-01-10T17:13:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eproasim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/eproasim/32/22818_2.png) [@eproasim](https://forum.playcanvas.com/u/eproasim)\
**Post date:** [January 10, 2025, 5:23pm UTC](https://forum.playcanvas.com/t/child-issues-after-instantiate-template-second-time/38732/10 "2025-01-10T17:23:48Z")

</div>

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