I have a simple game of a kite flying through simple square colliders.
When tested in the editor everything is fine. But when it is built for Android the colliders won’t work after reloading the scene several times.
So the BoxCollider2D is working for the first round but after reloading the scene couple times it won’t work. I tested it on (Samsung Galaxy S5 & LG G3) and I noticed that this behavior occurs after the game have dropped the frame rate.
I don’t know if this worth mentioning:
I tried to have the player as a prefab (as a solution) and re instantiate it in the loading of the game as follows:
void Awake () {
Vector3 pos = new Vector3 (-2.79f,-1.7f,0f);
Instantiate (player, pos, transform.rotation);
}
but nothing changed.
the trigger is as follows:
![void OnTriggerEnter2D (Collider2D other) {
if (other.tag == "Kite") {
Instantiate (explosion, kiteParent.transform.position, kiteParent.transform.rotation);
kiteParent.SetActive(false);
gameController.GameOver();
Invoke("KillExplosion",2.0f);
]
}
}][1]
This is the code for restarting the level.
public void Restart()
{
gameOver = false;
restartBtn.gameObject.SetActive (false);
pauseBtn.gameObject.SetActive (false);
SceneManager.UnloadScene(SceneManager.GetActiveScene().buildIndex);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
and the collider on the hazard as in the printscreen below:
[Update - Issue Resolved]
Ok, I found the reason causing this issue.
Make sure to assign the instantiated object to a GameObject variable as the compiler can’t destroy the instantiated assets which causes the game object’s collider not to work properly.