- Home /
How to access the persistent listener gameobjects on a button?
Hello. I am wondering if it is possible to do what I ask. Lets say I have a button with 3 persistent listeners (all gameobjects) which I have dragged and dropped into the button's fields from the inspector. How can I then reference these gameobjects in code? Thank you for reading.
Answer by Hellium · Apr 29, 2019 at 11:39 AM
You can't access the gameObject itself, not event the component where the function is declared.
The only thing you can do is to change/add/remove the callback of the event using the UnityEventTools
class, but keep in mind that this class is declared inside the UnityEditor
namespace, thus, making it inaccessible from a built game.
https://docs.unity3d.com/ScriptReference/Events.UnityEventTools.html
However, if you could explain what you are really trying to do, another solution can be found maybe.
Ah. That is unfortunate to hear. I was hoping to make an array of all of the gameobjects on a button. Only in the editor, not in the game.