Hi all,
I was wondering how one would go about implementing level streaming/room loading as in the classical Resident Evils (0, REmake, 1, 2, 3)
As most of you probably know, in RE if you’re in a room then you’re pretty much in isolation from actors/entities/objects in other rooms, so a zombie can’t break in and attack. It’s like there’s a separate memory space for each room.
My guess is that when a player enters a room, they load the room with whatever tickable objects in it (zombies etc) and the background renders. When you exit the room, they check if the room should save anything (*), unload it and load the new room.
(*) Take for example the pictures with the crows room in RE1 (@24:15), if you mess up the puzzle and exit the room and re-enter, the puzzle would reset, but if you solve it correctly then exit/re-enter the puzzle had already been solved. I’d imagine there’s a save that’s done to the room upon player exit if the player solves the puzzle, and a load when the player enters.
I would like to achieve a very similar thing. I know that they probably couldn’t load more due to hardware limitations, but most of the times I find myself seeking ways to achieve the results/outcomes of those limitations (Most the times those limitations end up playing a major role in enhancing the overall experience of the game they were implemented in (the fog in Silent Hill 1, the static backgrounds/cameras in RE etc)). I was wondering how one would go about implementing that in Unity. I thought about two approaches, but before I talk about them let me mention some of the prerequisites I want to meet in this system:
- Each room is isolated, enemies in other rooms have no way of interacting with you/breaking in.
- Fast loading times when entering rooms (I usually play the PC version of RE3 just because I can skip the door loading scenes…)
- The ability to save room state upon exit if necessary (this is a room-dependent thing)
My thoughts/approaches (just theory, haven’t tried them in practice yet):
A) Use a separate Unity Scene for each room.
Pros:
- It easily ensures the room’s isolation.
- For saving/loading, I could keep track of the current loaded scene and use some of Unity’s callbacks like OnLevelWasLoaded or OnDestroy/OnDisable & Awake/OnEnable in a per-scene manager behaviour.
Cons?
-
I’m not sure about loading times, I’m kinda worried that some rooms will have longer loading times than others…
-
There’s gonna be a lot of small rooms, it could be an overkill to use a separate scene for each of them…
-
More scenes = more management + extra care needs to be taken cause from my experience scenes are fragile and could corrupt pretty easily which means I should not rely a lot on the editor to set my things up and go data-driven (which I’m already doing) and do the least amount of config to re-setup the scene if necessary.
B) Load a relatively big rooms chunk, e.g if I had a two story building, and the player’s in the first floor, I’d load all the rooms in that floor - they’re all in one scene. When player goes to the ground floor, I’d load the whole ground floor. Take for example the room in this video (the bg is pre-rendered btw :p) - I’d load it and all the rooms in it in one scene. But then to achieve room isolation I’d have to come up with a system that, for instance give each room an id, and keeps track of which room the player’s currently in and deactivates all objects in the other rooms (I imagine the whole room would go under a GameObject for organization purposes and to make it easy to disable/enable rooms?) - Saving/loading wise, not much of a change. I’d still have to save/load things when player exits/enters a room or changes scene.
Here’s an old map of that floor:
Pros:
- Less scene management you could argue.
- Faster loading times when traveling between rooms since they’re already loaded.
Cons:
- Room isolation is not as perfect. There could potentially be bugs where entities in other rooms might remain active, or don’t initialize properly or Idk… But I don’t think it’s a huge deal I just haven’t tried it yet…
- Larger scene = harder to reconfigure/rewire if it gets corrupt.
My questions:
- Are those two approaches decent? Which do you think is best and why?
- A lot of the times we’re in a tunneled vision and can’t see outside of it, that’s why we ask for others’ opinions/thoughts: do you see something I don’t in those two approaches? (in particular: potential bites, gotchas and caveats)
- Can you think of a better approach?
Those were my 2 cents, can’t wait to hear yours!
Thanks in advance for any help/ideas!
EDIT More on approach B: maybe each room would be a prefab?