No collision detection in built version

Hi everyone,

when playing my game in the editor, everything works fine: I shoot some bullets and I rely on the physics system to inform me when the bullet hits the terrain or another collider.

I now have built the game and I try to play it. Unfortunately, the bullets now pass through the terrain and any other collider. I don’t seem to get any OnCollisionEnter messages anymore.

I use Unity V5.1.2f along with Oculus drivers 0.6.0 beta (I think; shouldn’t make a diff since it works in the editor)

Has anyone encountered a similar problem?

I’ve checked this further and actually, the colliders are there. I manually do a raycast from the camera into view direction and I display the object that got hit. It reports the right object.

So, basically, it seems that the collision detection doesn’t work at all… At least, I don’t get any OnColliderEnter callbacks.

Ok… so I found the problem:

Actually, the collision detection was Ok. The OnColliderEnter function was called and the code within the function was executed. What that code did was to instantiate a prefab of the detonator assets. This prefab has not stored the shader references as an object, but actually does a Find to select the right shader.

While the editor always has all shaders available, the build of the game only includes which is actually referenced. Any asset that is found via Find and which is not in the Resources folder, will be skipped during build and, thus, is not included in the created game.

There are 2 solutions to this:

a) create a “fake” material using the shaders needed and placing this material in a resources folder.

b) use the “preloaded assets” settings of the Projects Settings → Player inspector.

Hope this helps others…