I have few questions related to overall game structure in Unity because during my experience time I have seen many developers code but all have different approaches for game development so I am posting this question so I can conclude which approach remains better for overall game structure.
For example, I have a 3d mobile game with 20 levels in it and levels you can put either in small or medium length section, I mean those are not too big to deal in processing.
Is it remain better to create 20 different levels prefabs in a single scene and load them when each one required? or is it better to create 20 scenes for these 20 levels of gameplay?
Prefab or scene which one creates overhead for the game engine?
If small or medium size mobile games, if we create and manage within a single scene then will it create any performance issue?
On multiple retry game (small but hard games), whether to load a game scene or load gameplay prefabs again and again? which one not create any performance issue?
Please share your opinion and knowledge regarding above my questions and I hope other members also found useful this post in future
Prefabs pretty much always better. You can easily break up a level into blocks that are stored as prefabs, making it much easier to iterate on things. Changes and corrections to parts of the level propagate to other parts.
Doubt it makes any difference once the game gets running.
Again, doubt it makes any difference.
Neither. Reset the level without destroying anything.
At least in the beginning, I would prioritize workflow over any performance considerations. When you are finalizing things you can test and make any changes you need to.
Are you Baking light & using light probes?
If so scenes is probably the less painful option. It is possible with prefabs but it’s more work.
You can still use prefabs to help create the levels.
I got your points and really thanks for sharing your knowledge
You raised new point in the discussion
If I was using a Prefab based approach then how can I do light baking in that?
Because whichever environment or characters I want to load those exist in Prefab and currently not loaded in the scene.
I usually end up with a hybrid approach. Big consistent things, like the UI, player or level backdrop all get their own scenes. Small consistent things, like buttons or enemies, get their own prefab.
Medium inconsistent things, like level layouts, tend to get their own custom save/load system.
I cant see a style thats ok with complete darkness if no direct light but ok Also, I have noticed that lights flicker in and out, and materials are strange looking until you bake, even if you untick both trealtime and baked GI this goes away. So the bake system must be doing something even when no GI is used.
But I guess this is something that proc.generated games have solved.
That is part of the solution.
The main problem with this approach is that it doesnt copy the light probe data.
You need some kind of work flow in order to use probes, here’s mine.
Light probe data used is the probe data from the last scene you loaded - this is how unity works. So I bake all my lighting in one scene for all prefabs along with the probe data. I then use the script from the forum post above which copies the lightmaps to a resource folder and gives the prefabs the information they need to load the lightmap data on the fly.
Then in my game I load this scene last so that it loads the light probe data - once you have baked the scene you can remove the prefabs from the scene or just disable them if you wish.
Then to use the probes for dynamic objects you need to set up probe anchors for each dynamic object. You can find the probe anchor reference on the renderer component. Then when the dynamic object moves around your level piece prefab you move the probe anchor object in a similar manner but within the light probe group.
If you are not using procedrual levels then just create a scene for each level and bake it
Most recently I used a scene for HUD, but prefabs for individual dialog boxes and popups which I found worked well (easy to work with).
I’ve also worked with a heavy scene layering approach and found it to be pretty good. This takes a bit more tooling to do well. I built a panel to quick/easy load in/out different layers as this was essential. I think this approach can be good if your UI needs are more on the complex end.
In terms of performance, I don’t think there is a significant difference, although if you are loading in large amounts of stuff - you will probably have an easier time getting very smooth transition using scenes (you have more control over how this happens) than you would with prefabs (since this is only instantiate and may cause a stutter if you’re loading in a ton of stuff).
It depends on what your doing and how your doing it.
We make a lot of AR applications for Hololens, which means that the location of things will be different each time (could be 0,0,0 one time, 150,150,150 another etc etc) due to user placing the scene / objects (general way AR apps on HoloLens work).
As such we have a hybrid approach. We load scenes which then have a component on themselves that allows them to reposition themselves at the anchor, allowing us to additively load bits and pieces in and out.
On top of that we also use prefabs which do a similar thing: get spawned and then move + anchor themselves to a location.
If we were not using this platform we would just use scenes for our purposes, which would give us the benefit of lightmap baking, occlusion culling, navmesh baking etc etc. Unfortunately these are things we have to go without