Unity Scenes 2: Keeping Objects When Changing Scenes (DontDestroyOnLoad)

preview_player
Показать описание
How to keep objects from being unloaded when loading a new scene.

Note: this video was made before Unity started showing DontDestroyOnLoad objects separately in the hierarchy, which is why this looks a bit different than what you see in the editor. Everything discussed here is still valid, but now you don't need to check the GameObject's scene property to see which scene it's in.
Рекомендации по теме
Комментарии
Автор

This video was made before Unity started showing DontDestroyOnLoad objects separately in the hierarchy, which is why this looks a bit different than what you see in the editor. Everything discussed here is still valid, but now you don't need to check the GameObject's scene property to see which scene it's in.

unityvideosjulienlynge
Автор

Very easy and to the point. Now I know how to save my SAVED items in my INVENTORY. I never need to return to previous Scenes in my game

arrcommdwr
Автор

I was having a big problem with player prefs and this... thank you for explaining it so well XD

SkullyP
Автор

Excellent information. Exactly what I want!!! Thank you Sir.

awwad
Автор

Could you add this function to plane detection for augmented reality?

businessstork
Автор

Hello, do you know how to save objects from arrays? because i have a function which tells what not to destroy but it destroys it either way do you know how to solve it?

sliceggjd
Автор

Thanks for this!! Will try it today for my game :)

bacayne
Автор

Doesn't this create all kinda issues with references to the object? You can't reference an object that is in a different scene. So if the original placement is in one scene, then it gets chucked into the ' dontdestroy' scene, any references to that object would cause errors. I'm not sure any advantage this method has over just having a scene with all your persistent objects, and then additive scene loading the other stuff, at least that way you are way less likely to screw up a reference since it wouldn't be allowed to compile in the first place.

PeterSedesse
Автор

Great and to-the-point tutorial. Could you please elaborate and show an example of how to check if a specific gameobject exists and delete it?

rafalkowalski
Автор

hi well what to do if i want it to be destroyed once the scene is reloaded?

psychTech
Автор

Ok, but let's say I want to keep the object only for some scenes and not for other. Like let's say I have music in the main menu that is playing in the main menu scenes, but when I press New Game and the game starts I want the music not the move in my game level. Pls help

fromthedeep
Автор

"I'm gonna call this SaveMe, " BLINK TWICE IF YOU'RE BEING HELD HOSTAGE

Before the nerds say 🤓🤓Akshually that was because the part needed to be saved to the next levels🤓🤓 its just a joke

knowledgeseeker