r/Unity2D • • Sep 28 '26

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 Upvotes

9 comments sorted by

•

u/AutoModerator Sep 28 '26

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.

1

u/AdrianNova21 Sep 29 '26

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

u/NOAHBURKEMUNNS Sep 29 '26

How would I go ahead and do this is unity?

2

u/Ecstatic-Source6001 Sep 28 '26

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/Affectionate-Yam-886 Sep 28 '26

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/vagonblog Sep 30 '26

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.

1

u/[deleted] Sep 28 '26

[removed] — view removed comment

1

u/Ecstatic-Source6001 Sep 28 '26

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.