UnityEvent with dynamic parameters not showing anymore in the Unity inspector

All of a sudden this happened to me with 2018.4.10f1, all of my DropDowns are now broken. All of the On Value Changed() events say and I can no longer assign Dynamic callback functions.

Edit: Updating to 2018.4.20f1 seemed to fix the problem…

1 Like

I have this in 2019.2.17, can’t see anything in the patch notes for .18, .19, .20 about the fix.

I have it when extending TMP_InputField to get access to the SoftKeyboard.

The problem is still there, in this case it happens to me when the UnityEvent is on the base classe I inherited.
The event is displayed on inspector but the event paremeters just dissapear.

I’m using Unity 2019.2.9f1

Samme issue here with 2018.4.9f1, it happened suddenly after working for a long time. Guess I will have to upgrade the project to latest 2018.4

UPDATE: Upgrading to 2018.4.24f1 fixed it for me. Hope nothing else broke

Using Unity 2019.3.12f and had the same issue. I ended up having to refactor some code to get it to work.
I had a door script that has a simple method that was called via a UnityEvent:

public void SetDoorState(bool newState)
{
    NewState = newState;
    m_animator.Setbool(m_IsOpenAnimBoolParam, newState);
}

The UnityEvent is plugged into an enemy spawn script that I want to open the door when the enemies are all dead.
It worked great until I decided to add a second bool param to the SetDoorState() method.

I tried:

[System.Serializable]
public class DoorParams : UnityEvent<bool, bool>
{
  public bool NewState;
  public bool PlayAudio;
}

[SerializeField]  private DoorParams m_OnCompleted;

//..
public void SetDoorState(bool newState, bool playAudio = true)
{
//..stuff
  m_OnCompleted.Invoke(m_OnCompleted.NewState, m_OnCompleted.PlayAudio)
}
//..

This exposed the appropriate method under the dynamic parameters section for the UnityEvent, but I needed a way to set the params independently in the inspector since I may want to open multiple doors and some may be far from the player and therefore not play any audio.

I ended up writing some some helper methods:

public void SetStateAudio(bool newState)
{
  SetDoorState(newState, true);
}

public void SetStateNoAudio(bool newState)
{
  SetDoorState(NewState, false);
}

private void SetDoorState(bool newState, bool playAudio)
{
//..stuff
}

I hate writing hacky code to get something done, but it will work for now. I may be able to write an editor script for it, but it seems like a waste of time for such a small feature.

I think I came across this issue, with 2019.4.4f1 which should be the newest LTS version so far…

So, according to this thread, it’s fixed in the most updated 2018.4.x, 2019.2.x, and 2020.1.x?

Fixed on 2019.4.8f1 LTS

6240692--687194--upload_2020-8-25_11-14-10.png

Same issue on 2019.4.14f1

2 Likes

I didn’t dig to a complete solution yet, but after some observations I’m able to correct the issue for my components. I noticed that this was working for me in some instances and stopped working after I introduced new event. The old events had still correct listeners, but adding new listeners to those events also stopped working. I’m using Git to version my game code. So I went to the diff and noticed that in .unity file when the listeners are assigned their “m_Mode” property/attribute is set to 0 in the case of old listeners (which are properly assigned) and 2 in case of new listeners. So I just changed “m_Mode” to 0 in that file and it shows up properly in Unity and works as expected.

Hope this helps others. I will still try to find what causes unity to think it should go with “m_Mode” 2, cause it’s obviously worked for me in the same version of Unity and stopped working after some actions. Upgrades for me had no effect what so ever.

Same problem on Unity 2019.4.26f1…

Same problem in 2021.1.6f1

Only started when I started using text mesh pro.

public UnityEvent<string, string> OnChatMessage;

isn’t showing up in the inspector… im using 2019.4.22f1. TMPro is in my project

It seems you need to create an empty child class as explained in the documentation for the events to appear in the inspector. Convoluted, unintuitive solution. I hope this can be improved in the next versions.

1 Like

For those that are still using Unity 2019.4.11 and having this issue. I confirm this worked for me.

I agree 100% in unity If the event has a param → T0 up to T3 one has to override the UnityEvent class to expose the event in the inspector.

Still having the problem with Unity 2020.3.30 and this doesn’t fix the problem.

Hi can you post the part of the code you are using to expose the event in the editor?

I just came across this issue in 2020.3.24f1. Dynamic methods are not showing in the inspector.

This is a major pain in the butt!!! The subclassing of UnityEvent does not fix the issue for me.

EDIT: After a bit of testing I found that they are broken on child classes. If the class is based on MonoBehaviour, then the dynamic methods work!! The class can implement an interface, this still works.

Audio sources in Unity have a falloff range, beyond which they will not play. Curious why you need to use code to prevent an audio source from playing? Couldn’t you simply set the audio source falloff to say 10 meters for the doors?

Thanks for the Insight. I wasn’t aware that Unity wont play the audio if not within range. Currently all my AudioSources are set with a Max Distance of 10 meters. Since my doors will automatically close after a set time, I really just wanted a Unity Event that I could invoke so that the associated scripts could do their jobs(IE: Play some Audio, Spawn some dust particles, Animate the door, etc). Thanks again for the info.