Why not audioSource in the DontDestroyOnLoad?

So, I used audioSource instead of gameObject. I understand the documentation says use gameObject, but so far, audioSource works perfectly ok.

Will I become unstuck later? I get why gameObject is used… Thanks.

DontDestroyOnLoad(audioSource);

I assume that this will be a problem if there were multiple audioSource, or sounds, playing in the script?

I think the reason this works for you Andy is because of this line in the documentation for the DontDestroyOnLoad method;

“If the object is a component or game object then its entire transform hierarchy will not be destroyed either.”

Personally, I would probably still use gameObject, as I believe it infers that the whole hierarchy would still be available, whereas knowing that audioSource is a component could be confusing.


See also;

Thanks Rob, I have changed it anyway, I was messing around to see what worked that’s all and was curious as to the differences here.

:):sunglasses:

1 Like

No problem, happy to help :slight_smile:

Privacy & Terms