How to register custom Events on MonoBehaviour

Hi,

so I’m currently trying to have a GameObject with a MonoBehaviour script on it, that I want to have inputs in the inspector for methods on other MonoBehaviour scripts.

So far I figured out that the way to do this is probably events.

In my specific case I have an array of 6 UnityEvents on GameObject A and I want to set a method M on another GameObject B to be executed when I call UnityEvent.Invoke() in method N on GameObject A.

I actually even got this far, so my inspector looks like the picture below.

My problem now is, that it seems that method M is never called after it should have been invoked by method N.

My code is:
GameObject A

public UnityEvent[] sectionEvents;
public bool[] useEvent = new bool[6];

private void ExecuteSector(sector)
{
    if (useEvent[sector])
    {
        Debug.Log("Invoking method");
        sectionEvents[sector].Invoke();
    }
}

GameObject B

public void BuildMenu()
{
    Debug.Log("Opening build menu");

    newBuilding = Instantiate(Lib.Buildings[0], MouseGO.transform);
    newBuilding.GetComponent<Structure>().SetCollider(false);
    playerState = PlayerStates.blueprinting;
}

Meaning the first Debug.Log() produces an output, but not the second, as it presumeably is never called.
Can anybody tell me what I’m missing?
I tried to read about it in the documentation, but the whole UnityEvent section is a bit minimalistic.

Okay, so as it often is, it was all my fault and it was a stupid mistake.
I simply confused the arrays indices, so for the button I was testing the invoke on, there was no UnityEvent set.

But if anybody is wondering if the way I did it is the right way to do it: yes it is.
Just make sure to know your arrays. :roll_eyes: