I have built a simple level and saved it as a scene. In my scene there is a hero and enemies.
Now for the next level I’d like to reuse my hero.
For enemies, I can use prefabs, that’s fine. But my hero is always one single instance.
Is it recommended to use prefabs for the hero too in order to use it for multiple scenes?
You can use [DontDestroyOnLoad] so the Hero gameObject doesn’t get destroyed on scene changes.
I instantiate my player at runtime from prefab.
I do this because, when you put an object onto a scene, while working in editor (not at runtime not as prefab), then every time you load that scene, that object will be created again in its original “editor-defined” state.
So, lets say you place your player on scene in editor, you set DonDestroyOnLoad on him. You start
the game, you go to next scene (next scene loads) everything is cool, your player is still alive (he survived scene transition because you set DontDestroyOnLoad), but, when you go back to the first scene, you find another player : ), because when this first, starting scene is loaded again, player is created again by default…
So, I’m beginning to think that actually every object should be a prefab. There is an article
Unity3D Best Practices | Glen Stevens' Thoughts in which, among other practices, this one is receomended:
“Use prefabs for everything. The only game objects in your scene that should not be prefabs should be folders. Even unique objects that are used only once should be prefabs. This makes it easier to make changes that don’t require the scene to change.”
Also, It seems to me, that most objects (every object that is not absolutely “static”) should be instantiated at run-time from prefabs (not placed on scene through editor). Because scene always reloads objects set in editor in their original state. I dont know how to avoid this if not instantiating objects at runtime, having full control over them.