# DontDestroyOnLoad only works for root GameObjects

I have this simple code, but it does not prevent the object it's attached to from being destroyed on load:

 void Start()
{
Debug.Log(gameObject.scene.name);
}


It also shows this Warning:

DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
wfb:Start () (at Assets/Script/wfb.cs:9)

DontDestroyOnLoad(gameObject); is on line 9.

If the game object is a child, the DontDestroyOnLoad() function will not work.