The religious behaviour may be a misfiring, an unfortunate by-product of an underlying psychological propensity which in other circumstances is, or once was, useful. On this view, the propensity that was naturally selected in our ancestors was not religion per se; it had some other benefit, and it only incidentally manifests itself as religious behaviour.
-Richard Dawkins, The God Delusion pg 174
This is a particularly difficult problem for materialists like Mr Dawkins to deal with since the historical evidence speaks strongly against the notion that everyone is borne as an atheist, or blank slate per John Locke.
However this presents a problem for the evolutionist. If it is true that religion is merely a survival mechanism, then it demonstrates the fact that the primary goal is not the production of true beliefs. If it is false, that religion is merely a survival mechanism, then we cannot dismiss it as merely a delusion.