Re-enabling canvas causes UI components to lose normal scaling

I have a canvas that has some images, buttons, etc.

It is used as an ending screen, so at the start of the game, it is disabled using the following code:

endCanvas.enabled = false;

At the end of the game, it is enabled using the same code:

endCanvas.enabled = true;

The canvas elements are becoming scaled after it is re-enabled.

Before game start (how it is supposed to look)

After game end (canvas enabled again, elements scaled)

I found a fix, but I cannot use it.

endCanvas.gameObject.setActive (false);


endCanvas.gameObject.setActive (true);

I think it has something to do with the UI rebuild that is triggered when onEnable for the gameobject is called, but that’s about it.

Thanks, in advance,

The enabled variable is used to activate/deactivate components, in your case, you probably want to deactivate the whole GameObject where that canvas is, so you can actually use gameObject.setActive (true); and gameObject.setActive (false);