I have this simple code, but it does not prevent the object it's attached to from being destroyed on load:
void Start()
{
DontDestroyOnLoad(gameObject);
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.