How to Instantiate a prefab button without an object reference error?
I'm trying to instantiate UI text elements with button components. The way I know how to do this is to make the UI element a prefab. The problem is that the button component needs a GameObject attached to it in order for the OnClick() function to work. And since I'm using a prefab (for the button), it requires the attachment to be a prefab as well. Since the button's attachment is a prefab and not an instance, I get the Null Reference Exception error when the button is clicked.
I'm wondering if there is a way to get this done so I can instantiate a working button with an instance reference?
The workaround I came up with was to have the button in the scene inactive, and then activate it from script. This can't be the only way right? Thanks in advance.