Using a UnityEvent as a parameter makes the function not show in the inspector

this is what im trying to do:

public void ShowAd(string placementId) {
       
        Advertisement.Show(placementId);
    }

public void SetAdFinishedEvent(UnityEvent e) {
        adFinishedEvent=e;
    }

public void OnUnityAdsDidFinish(string placementId,ShowResult showResult) {
      
        if (showResult==ShowResult.Finished) {adFinishedEvent.Invoke();}

    }

If you never used ads before, then OnUnityAdsDidFinished runs automatically when the ad finishes.

In the inspector, on a button I want the OnClick to have:

SetAdFinishedEvent()
ShowAd()

So I can decide what I want to happen after the ad is shown. But if I use a UnityEvent as a paramater, then I can’t see that function in the inspector.

Is there a work around? The only way i can think of is to just have a different function for every different function I might want to use.

I found a solution here from MrLucid72: Enum as a function param in a button OnClick - Questions & Answers - Unity Discussions

Now my code looks like this:

    public void ShowAd(EventHolder e) {
       
        adFinishedEvent=e.event1;
        Advertisement.Show(e.strng);
    }




    public void OnUnityAdsDidFinish(string placementId,ShowResult showResult) {
      
        if (showResult==ShowResult.Finished) {adFinishedEvent.Invoke();} else
            if (showResult==ShowResult.Skipped) {adSkippedEvent.Invoke();} else
                if (showResult==ShowResult.Failed) {adFailedEvent.Invoke();}

    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class EventHolder : MonoBehaviour
{
    public string strng;
    public UnityEvent event1;


}

I make an EventHolder component on my button, then I pass it into the ShowAd() function. And to set the parameters, I just edit it from the EventHolder component. I can use multiple parameters like this too.

1 Like