All Unity projects must solve the problem of initializing instantiated prefabs.
PrefabController
is my attempt to demonstrate a standard solution to this problem in Unity.
When a prefab is instantiated, OnEnterScene
should be called immediately to inject necessary scene data, such as cameras, lighting info, and other dependencies.
All prefab controllers ought to be unit tested, and OnEnterScene
provides a clear interface to pass initialization data within a test scenario.
Scenes and prefabs are similar concepts in Unity.
Both are modular assets intended to be reused.
Both contain a tree structure of GameObjects.
But despite having completely separate creation workflows in the Unity editor, the key difference between the two is subtle and rarely alluded to: scenes are self contained singletons, while prefabs are not.
Prefabs cannot exist in their own, they are always instantiated into a scene, and PrefabController
only attempts to formalize this relationship.