On my current project, I have each level in a different layout, and since the start of it I wanted to create a single HUD that would work with each.
First I created the HUD dynamically when I load the level, but this is a pain to create and maintain if the HUD is complex.
Then I created a HUD on the first level and made it global. This works - except if you jump into a different level - if you are testing or if you are continuing a saved game.
And today I found the solution... which basically involves checking to see if the HUD is loaded - and if it isn't switching the layout to the HUD layout and then switching straight back - with the HUD kept because it is global.
I am very happy with this!
Develop games in your browser. Powerful, performant & highly capable.