Im relatively new to game development and am looking for advice.
I 'm just working on the first level for my game and am now trying to decide whether i want the whole game to be in one scene or multiple.
The game is divided into 9 main areas, each with its own music, bosses, types of enemies, art style etc. I am currently thinking of subdividing more complex areas into multiple “rooms” probably similar to hollow knight or deaths door or pretty much anytyhing in the same genre.
My question here is, should i have one big scene, separate scenes for each area, or sperate scenes for each room? How easy is it to pass lots of data on from one scene to another, will need to preserve data such as health, coins, whether or not a boss has been defeated, NPC dialogue stages, other world events, etc…? Is it easier to do this or to progressively load and unload areas of the world based on character predicted movement (have seen a lot of talk about additive level loading)? Will making it in one/nine scenes make the game laggy or increase performance requirements? When reloading a scene, does it retain the data from last time it was loaded?
Note, i am not using tilemaps, all handdrawn sprites, so wont need to load and unload tile maps.
Does anyone know what bigger studios do with their games?
Keeping persistent information is trivial, that’s just a GameManager of some type set to live through scene changes.
Why not start by making it all in one scene, roughing it out, iterating on it, and if it gets unwieldly, chop it all apart. It’s super-easy to have multiple scenes and use extra GameObjects (sort of as folders) to organize stuff.
ALSO, please consider using proper industrial-grade source control in order to guard and protect your hard-earned work.
Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).
As far as configuring Unity to play nice with git, keep this in mind:
Here’s how I use git in one of my games, Jetpack Kurt:
Using fine-grained source control as you work to refine your engineering:
Share/Sharing source code between projects:
Setting up an appropriate .gitignore file for Unity3D:
Generally setting Unity up (includes above .gitignore concepts):
It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.
“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards
For a simple singleton construct, I always reach for this no-fuss no-muss solution:
Simple Singleton (UnitySingleton):
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:
These are pure-code solutions, do not put anything into any scene, just access it via .Instance!
If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like:
public void DestroyThyself()
{
Destroy(gameObject);
Instance = null; // because destroy doesn't happen until end of frame
}
We’re doing a 2D metroidvaniaish thing, and we’re using multiple scenes. Whenever we enter a scene, we load all the adjacent scenes, and when they’re loaded we deactivate the things there. Then, whenever you move into the scene, we can just activate them and move the camera, so there’s no load screen.
This works well, but it’s a lot harder than just doing the Hollow Knight thing of clearing the screen to black, and then loading a different level entirely. If you’re new to this, that’s probably the way to go about things. Moving enemies out of the scene they started in gets pretty complex surprisingly quickly if you need to unload their scene and then reload that scene all the while having vision of the enemy on screen.
I wanna to do something exactly as hollow knight, what do I need?
Right now I have no ideia how to make my character keep the same position as he enters a new scene and goes back to the scene before
You need to know where the scenes are in relation to each other. The easiest way of doing that in Unity is to use multi-scene editing and simply place the objects in the new scene next to the objects in the old scene. This means that it’s easy to check that transitions line up (you just load both scenes and check that they do), and that moving a character from one scene to another is “free” - the character is already at the correct position when it moves.
The alternative is to use linked doors. This simply means that at each exit from a scene, you have a collider with a script that says “this door goes to door X in scene Y”. So when you enter it, you load scene Y, find door X, and put the player there.
This allows a lot more flexibility in shuffling rooms around, though it’s generally more work to make doors, and it’s easier to make a mistake. It becomes pretty important to have static tools to check through the game for doors that lead to nowhere.