Load UI objects at run-time

Hey,
I’m currently using a singleton pattern, that is created at run-time when it’s needed, so it isn’t just sitting there in the scene.

I’m loading the UI prefabs from resources when I need them since the singleton is not scene-dependent and wherever the scene the player is on, the manager keeps working. I’ve seen this method in a post, and I found it interesting, so I’m implementing it in my current project.

Though I’m feeling a little weird about this and I feel that there is a better way to do it. Since we load the UI and our singleton is not on screen until run-time, I can’t just reference the UI elements on the inspector, instead, I need to find everything on my prefab for just then manipulate them according to my needs, which takes time.

My question is if this approach is bad and if it is, is there a better way to do it?

Let me explain you a bit of a trick.

First, Create an UI under Parent panel. Design your UI as you want. Make a script which you will apply to parent GameObject. Create variables for all references for all the UI object under the script you have created for parent object that you would like to use in code. Assign references to those in the inspector. Now, create a prefab of the parent game object. Delete it from the scene. If you can’t have references of the prefab in the any of the scene game object, then you can use Resources.Load<>() method to load an game object in runtime. for that you have to place prefab in the Resources folder.