Buttons on disabled canvas still catching keypresses

I have a weird bug in my code where pressing space seems to be triggering a button on a canvas that’s recently been disabled.

So at the end of my game I show a canvas with 2 buttons, “back to menu” or “continue playing”.
alt text
“Keep playing” calls a function which disables the canvas. I use this code below:

goalCompleteCanvas.GetComponent(Canvas).enabled = false;

But then if I press space, it calls the function of the button that was clicked again, even though the canvas was disabled and the buttons are hidden. If I press a cursor key and use space I can actually select the other button too.

How can I hide this canvas and stop any of the buttons from being triggered?

Oh wait, I could just disable the gameObject instead of the component.

No idea why I didn’t think of that.

I’m an idiot.