- Home /
Is it possible to select a prefab during the build process?
Hello,
We use an automated build system for our project. Locally, devs would like to use a prefab B1 (linked to the script B1). But the remote build should use the prefab B2 (linked to the script B2). Both classes B1 and B2 inherit from the class A.
If these were simple classes I would use a preprocessor directive to control the instanciation, but I'm not sure this is possible with prefabs. Is it? And if not, do you have best practices or advices to solve this kind of problem?
Thanks.
Answer by kork · Feb 09, 2016 at 07:44 PM
You could use a prefab loader component, to move the issue into the realm of scripting, something along the lines of
public class PrefabLoader : MonoBehaviour {
public GameObject productionPrefab;
public GameObject developmentPrefab;
public void Start() {
#if DEBUG
var instance = GameObject.Instantiate(developmentPrefab);
#else
var instance = GameObject.Instantiate(productionPrefab);
#endif
// attach to parent
instance.transform.SetParent(transform.parent, false);
GameObject.Destroy(gameObject);
}
}
Then you just create an empty game object with this component, link the two prefabs B1 and B2 into the public fields and then use the prefab loader instead of the real prefabs.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Why does Prefabs loose children and effects when instantiated on Windows Phone 8? 0 Answers
Prefabs are instantiated in editor but not in executable 2 Answers
How can I get Unity to respect mcs.rsp changes between multiple builds? 0 Answers
automated build issue - UnityLookForNewInputDevices 1 Answer