Don't understand parent-child Game session persistence

Hi, in Complete Unity 2d course lecture 106, Rick puts canvas UI under Game Session to persist.

I don’t understand this conceptually,

I understand the general object parent-child relationship as in objects, but how parent’s script can affect child if its under it or not… A bit confused… What can we do more with this technique?

Hi Pompei,

Welcome to our community! :slight_smile:

The idea is the following: We want to make the Canvas UI game object persistent. Instead of creating another script for it, we parent this game object to the persistent Game Session game object.

Children get destroyed along with their parent. By default, all game objects are non-persistent. If the parent persists, the child persists as well.

Did this clear it up for you?


See also:

Thanks for the Answer Nina,
So it’s not much about any script relationship between parent-child but only parent as an object, if not destroyed, their child also not destroyed hence it persists all objects down the tree. But we can override this right, like I can explicitly destroy child object via script but parent can persist?

Exactly. :slight_smile:

If you destroy the parent, the parent including its children get destroyed. If you want to destroy a child of a persistent parent, you have to destroy the child manually with Destroy().

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms