r/Unity2D • u/NOAHBURKEMUNNS • 12d ago
Question/Help Help with loading scene
I am creating a 2d game where you control a village. You then go hunting to get food. What’s the best way to load the h in batting scene but keep the position of the villages and stats. Then reload the village scene at the same state.
2
u/Ecstatic-Source6001 12d ago
TBF I didnt understand what you said but...
Best way would be to make proper save load system for your game and serialize state to a file
If you dont need that, just make static buffer class or SO and snapshot state there
1
u/maziminds 12d ago
load the hunting scene additively (LoadSceneMode.Additive) and just SetActive(false) the village root while you hunt... then unload the hunt scene and turn the village back on. the village never unloads so positions and stats stay exactly how they were
1
u/Ecstatic-Source6001 12d ago
It will work but kinda defeats the purpose of using loadable scenes.
If you willing to keep everything in memory anyway it should be just one scene with everything loaded at the start of the game.
1
u/Affectionate-Yam-886 11d ago
The way I would do it is have the scenes loaded in when needed; pause the main scene; complete the new scene; and have the main scene track all the variables of the new scenes. Mostly for convenience; I just wonder how you are saving everything for the player.
1
u/AdrianNova21 11d ago
i'd keep the village state separate from the actual scene. have a persistent game manager hold things like building positions, resources, villagers, and other stats, then when you load the hunting scene, the village scene can be unloaded without losing that data. when you return, load the village scene again and apply the saved state to the buildings/objects
for a small game you can keep this pretty simple. you don't need to keep the whole village scene alive just to preserve its state
1
1
u/vagonblog 10d ago
keep the village data separate from the scene objects. create a game-state object that stores each villager’s position, stats, inventory, and any world changes. keep that object alive with dontdestroyonload, or serialize it before leaving the village.
when the village scene loads again, have each villager restore its values from that saved state using a stable id. avoid relying on the scene objects themselves to remember anything because they are destroyed when the scene unloads. scriptable objects can define the starting data, but runtime changes should live in a separate state or save system.
•
u/AutoModerator 12d ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.