I’m working on a game in which there is a lot of screens that use same assets (sprites) but with a different layout. I was wondering if I should use prefab for each screen or if I should create/save layout informations and then re-create screens on the fly. Depends if prefabs have a significant cost/weight or if they are only data/containers that describe a GameObject in which case maybe it’s not a problem to use a lot of them.
So, are prefab an optimized way to store different GameObjects using same assets or not ?
You can have as many prefabs as you want which reference the same sprite for example. The sprite will be only once in your final build. The same goes for objects in a scene.
In your case however I’d rather go with a custom data format that describes your layouts, then instantiante and position prefabs as necessary on the fly.
Though the “cost” is very minimal, and nothing to worry about, like @blizzy said, if there is a lot to manage, building a data structure is can be much more efficient on the development side. You can make tool/tools to manage them as simple or complex as you want. And if you are doing mobile or desktop and you are going to be adding more levels to your game, having them in a data structure instead of prefabs, means you can add new levels at any time without have to do a client update.
Thanks for your answers. I get the chance to push the reflexion a bit further. All the screens with their layout would be set-up by an artist - so he will need to create and modify existing screen. That’s why I thought prefab too - in order to allow the artist to manage them easily.
If not prefab for each screens what about one prefab acting like a screen template and an editor extension that allow to save the actual screen prefab configuration into a ScriptableObject ? The editor extension should have the ability to save a configuration but also to iterate through them in order and apply a configuration to the screen template.
Are ScriptableObject a good idea for handling data structure or should I go with XML/JSON instead ?