Hi, I’ve been trying to figure this out for a few days and have come up empty so far.
I just finished the advertising lecture and implemented the “Continue” button. But, when I click it, the game crashes giving me an error saying:
MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
After a lot of trial and error I think I figured out what is going on but I can’t figure out how to fix it.
What seems to be happening is the clickable area for the “Play Again” button overlaps both the “Continue” button, the “Return to Menu” button, and other parts of the menu.
Another odd thing is the clickable area for the “Play Again” button does not completely overlap the “Continue” button. It only overlaps the right two-thirds or so. This is how it works:
If I click on the “Play Again” button it all works fine. If I click on the black space between the “Play Again” button and the “Continue” button it works as expected. That is, nothing happens because no button is being clicked on. If I click on the left 1/3 of the “Continue” button it works as expected - the ad shows and I can close the ad and continue playing the game.
But, if I click on the right 2/3rds of the Continue Button or any place right of the Continue Button (the “Return to Menu” button or even any part of the screen right of that) the PlayAgain function that is tied to the “Play Again” button runs. This function even runs if I click the area of the screen below the “Continue” button, the “Return to Menu” button, and the area to the right and below of the “Return to Menu” button .
I determined that the PlayAgain function was running as a result of these clicks by putting in debug statements to print out to the console what part of the code is running when it crashes.
I also tried disabling the “Play Again” button by unchecking the check mark in the inspector that makes my Play Again button inactive / invisible. When I did this, all the other buttons worked properly and clicking elsewhere on the screen does not run the PlayAgain function.
I also tried debugging it by leaving the “Play Again” button visible but unchecking “Interactable” and again the other buttons worked properly now.
So this leads me to believe there is something wrong with the Play Again button and how its clickable area is working. The button itself looks like the correct size on screen. When I select the button in the scene view the outline seems to only surround the button. The outline doesn’t seem to go outside the borders of the button from what I can tell.
I also looked at the child text of the Play Again button and as far as I can tell it is fine too. When I select the child text in the scene view its outline also does not go outside the borders of the button.
And I went back through the lecture where the “Play Again” button is implemented and it seems correct to me. That said, I’m sure I must have missed something or done something wrong.
I just can’t seem to find the issue. If helpful, I’m using Unity version 2021.3.14f1 Personal.
Any thoughts on what might be going on and where to investigate? Happy to share my code if that’s helpful.
Thanks.