prevent UnityEvent invoking a not active gameobject

Hello Unity friends,

I have a class which uses UnityEvent as public property, so I can fit it using the Inspector, this UnityEvent points to another object which can be active or not active; when the target object is not active, I receive an error message saying I’m trying to Invoke a function in a non-active object, it’s cool!
but here is the question:

how can I do check when UnityEvent target gameObject is active or not active? This way, I can avoid calling it when the object is not active.

A clarification, I don’t have the gameObject reference, my only connection with him is the UnityEvent variable.

I’m not sure if it’s the best way of doing this, but it worked and considering the time I had, I needed to find any solution.

here is this:

                        bool valid = true;
                        //UnityEvent ue is coming from a different object
                        for (int i = 0; i < ue.GetPersistentEventCount(); ++i)
                        {
                            UnityEngine.Object o = ue.GetPersistentTarget(i);
                            if (GameObject.Find(o.name)==null)
                            {
                                valid = false;
                                break;
                            }
                        }

                        if (ue!=null && valid)
                            ue.Invoke();

Good: it works!
Bad: if I have more than one object to be Invoked in the same UnityEvent, and one of them is not active, the other will never be Invoked.