Hey guys I worked in a company and we are experimenting with new ways to improve our current workflow.
So far we have always used prefabs as a collection of art assets and the individual scripts it needs, all
balled together in a composite game object.
Now this has always worked great so far in a small team, but we figured if we were to proceed further down the road we will eventually need to separate scripts (logics) from the art assets, in other words, game objects will not contain scripts, only art assets.
Now the problem is logics still need to have a way to refer to the art assets, and one way is to use Gameobject.Find during runtime, but is there a better way to do this considering that art assets may not be immediately available in the scene during runtime and some may be loaded into the project dynamically?
Another problem is the overhead of using AddComponent during runtime, especially on the mobile platform, because it is essentially calling a smaller version of Instantiate, which is expensive, one way we thought of to prevent this overhead is to have a controller script in the scene acting on the art asset instead of adding component, but as usual, is there a better way of doing this?
Was hoping somebody who has been through these things can share with us some of their lessons and some of the current workflow they are adopting.
Well, if you really want to seperate the logic from the art / models it should be done the other way round. A game consists mainly of logic. Art and models aren’t needed. They are just “visual sugar”. So build your objects and prefabs with just empty gameobjects and scripts. The models can be referenced by the scripts and instantiated either at runtime or inside the editor with some help of editor scripts.
If you have quite complicated object structures you might consider creating some sort of prefab factory which should create your final prefabs in the editor. A few simple Editor scripts can be quite powerful.
“Now this has always worked great so far in a small team, but we figured if we were to proceed further down the road we will eventually need to separate scripts (logics) from the art assets, in other words, game objects will not contain scripts, only art assets.”
It sounds you’re going against the engine philosophy. A GameObject should be a collection of Components, and Components add behaviour (behaviour as something more general than a MonoBehaviour script). I can’t see why you want a GameObject to only have art assets and not logic. What will you do with, for example, a Collider? Or a RigidBody? Do you consider them art assets? You usually setup the collider in relation to the 2D or 3D model used by that GameObject. Will you use the Transform itself? It’s just logic. You’re imposing a really arbitrary rule there that will make things a lot more complicated than they should. Can’t imagine what will you do if you try to make a multiplayer (networking, not local) game.