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.

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.