- Home /
OnCollisionEnter Not Working After Game Build
This code works great in the editor, but after I build the game (I've tried building both standalone and web applications) the OnCollisionEnter function no longer runs. If it works correctly, when the player runs into a monster the game ends. Here's the code:
void OnCollisionEnter(Collision collision)
{
if (this.tag == "Player" && collision.collider.tag == "Monster")
{
game.gameOver ();
}
}
Any ideas on why this wouldn't work after the build?
@nodnarbisc, are you sure this code is not running? I mean have you done some debugging to verify it is an issue with the collision? It could be a problem in gameOver(). If you are sure it's in this method, I have no ideas. Otherwise, please post gameOver().
@supernat Yeah I'm fairly sure its the OnCollisionEnter that's not working because I call game over() elsewhere and it works. Is there some build setting I need to change that might cause the built program to run differently than it does on the editor?
I think you should post your gameOver(). Everything looks fine up there.
@APenguin, @supernat Here's the gameOver() code. Not much going on here.
public void gameOver()
{
gameOverText.text = "YOU DIED. Press 'R' to restart.";
over = true;
}
I run this code either when the player hits a monster or if the player falls off the map. It runs when the player falls off the map because I use an OnTriggerEnter().
Did you try the last recommendations? Did they work? If you found a satisfactory answer to your question please respond it with the solution, that will be very helpful for future reference. Thanks for your comprehension, Unity Support.
Your answer
![](https://koobas.hobune.stream/wayback/20220613132652im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Small resolution + full screen = everything is blurry! 0 Answers
My character falls of the map when build, but works ok in the editor 0 Answers
Unity changes the collisionDetectionMode in builds 1 Answer
2issues: Xbox Controller axis returns value that's constantly changing and a build problem. 2 Answers