- Home /
How is a Button component able to access a method on a prefab?
I'm just getting started with Unity and I have some questions around the nuances of the Button component.
I find that a Button component can call methods against a prefab if you drag that prefab into it's OnClick list. How is it able to do this without the object being instantiated in the scene?
It's just a general question that I feel would help me better understand what's going on under the hood.
Thanks in advance!
Your ter$$anonymous$$ology is a little off so I might be confused as to what you're asking but I can answer what OnClick is storing and doing.
Essentially OnClick is a delegate that holds a function [Think of it like a variable of a method type] When it's triggered "On click" it will Invoke the function that is put into the OnClick Property.
Answer by JuanDLRR · Feb 24, 2017 at 08:15 PM
Hi!, I hope this is not being too late. I don't know if it will help you, you can drag your button code to your whole Prefab Gameobject, if that is a button, you can drag the button action from your own prefab gameobject with your respective code inside them. That's the way you can use a method in a prefab component. In that order it will be a Prefab programmed component.