Search Unity

UnityEvent with dynamic parameters not showing anymore in the Unity inspector

Discussion in 'Editor & General Support' started by Dorhan, Sep 17, 2019.

  1. Dorhan

    Dorhan

    Joined:
    Oct 3, 2015
    Posts:
    2
    Hi there!

    I have a problem for a few days that didn't exist before: UnityEvent no longer manages parameters. At first I thought it was related to the Unity version because I updated to 2019.3b, even returning in 2019.2.5f1 the problem exists.



    As you can see in the image, the "dynamic" elements are no longer displayed and the type is not present next to the event name.

    The code is extremely simple:
    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using UnityEngine.Events;
    5.  
    6. [Serializable] public class VoidEvent : UnityEvent { }
    7. [Serializable] public class BoolEvent : UnityEvent<bool> { }
    8. [Serializable] public class IntEvent : UnityEvent<int> { }
    9. [Serializable] public class StringEvent : UnityEvent<string> { }
    10.  
    11. public class Cube : MonoBehaviour
    12. {
    13.     [SerializeField] VoidEvent voidEvent = null;
    14.     [SerializeField] BoolEvent boolEvent = null;
    15.     [SerializeField] IntEvent intEvent = null;
    16.     [SerializeField] StringEvent stringEvent = null;
    17.  
    18.     public void OnVoidEvent()
    19.     {
    20.         Debug.Log("OnVoidEvent");
    21.     }
    22.  
    23.     public void OnBoolEvent(bool value)
    24.     {
    25.         Debug.Log($"OnBoolEvent {value}");
    26.     }
    27.  
    28.     public void OnIntEvent(int value)
    29.     {
    30.         Debug.Log($"OnIntEvent {value}");
    31.     }
    32.  
    33.     public void OnStringEvent(string value)
    34.     {
    35.         Debug.Log($"OnStringEvent {value}");
    36.     }
    37. }
    38.  
    I've tried the same code on another computer, the same problem exists. I'm on a mac using Visual studio code and Unity 2019.3b and 2019.2.5f1.

    Edit: It works in Unity 2019.2.4f, look like it's a regression
     
    Last edited: Sep 17, 2019
  2. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    13
    I've experienced the same problem.
     
  3. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    111
    Hello! This issue sounds very similar to another issue: https://issuetracker.unity3d.com/is...e-callbackcontext-set-as-their-parameter-type

    This issue is already fixed in 2020.1.0a5, 2019.3.0b4 and above. Also, there is a backport opened for a review for 2019.2 stream. To work around this issue, you'll have to upgrade to specified versions or above, or use 2019.2.4f1, since the regression was indeed introduced in 2019.2.5f1
     
  4. Dorhan

    Dorhan

    Joined:
    Oct 3, 2015
    Posts:
    2
    Thank you for the clear response! I saw the issue on the issues tracker a bit late, sorry for the noise.
     
    Domas_L likes this.
  5. gyd

    gyd

    Joined:
    Nov 9, 2012
    Posts:
    15
    workaround:
    Code (csharp):
    1.  
    2.     [SerializeField] VoidEvent voidEvent = null;
    3.     [SerializeField] public BoolEvent boolEvent = null;
    4.     [SerializeField] public IntEvent intEvent = null;
    5.     [SerializeField] public StringEvent stringEvent = null;
    6.  
     
    MaZy likes this.
  6. ofuscapreto

    ofuscapreto

    Joined:
    Jan 14, 2016
    Posts:
    1
    This issue is not fixed in 2019.3.0b7, I've tested. So, I have to downgrade my project to 2019.2.4f1 (which I've tested and worked in a new test project) to make it work? I tried that, but doesn't work for a variety of errors.

    This completely destroyed the architeture of my project. Don't say it was fixed in 2019.3.0b4 and above, because it's simply not true.
     
    brodie059 likes this.
  7. JFortunato

    JFortunato

    Joined:
    Dec 11, 2012
    Posts:
    2
    Indeed it's not fixed.
     
  8. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    Last edited: Oct 22, 2019
  9. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    111
  10. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    The basic case seems to work in 2019.2.9 I can confirm. I was having the problem in 2019.2.6 and .9 fixed it.
     
  11. Akira_Kido

    Akira_Kido

    Joined:
    Dec 20, 2015
    Posts:
    5
    This seems to be an issue with 2018.4.9f1 as well...
     
  12. petersvp

    petersvp

    Joined:
    Dec 20, 2013
    Posts:
    63
    It's in 2018.4 LTS as well.
     

    Attached Files:

    bramble-operations likes this.
  13. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    This is still an issue with the latest 2019.3.03f...

    This does not show up in the inspector:

    Code (CSharp):
    1. public class TextUnityEvent : UnityEvent<string>
    2.     {
    3.     }
    Then in the class itself

    Code (CSharp):
    1. public TextUnityEvent onErrorEvent;

    Neither does this (directly in the behaviour class):
    Code (CSharp):
    1. public UnityEvent<string> OnLoginError;
    It has been several months... what are you doing???
     
  14. kkl888

    kkl888

    Joined:
    Dec 6, 2014
    Posts:
    55
    Same to me too~ I always get the static value. Using Unity 2018.4.10f1
     
  15. sindrijo

    sindrijo

    Joined:
    Mar 11, 2014
    Posts:
    13
    Same/or similar issue in 2019.2.17:
    TemplatedUnityEventFieldBug.PNG

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Events;
    4.  
    5. /*
    6.     UnityVersion: 2019.2.17
    7.     Bug Description:
    8.     Incorrect property-drawer is used for templated private fields in serializable classes.
    9.  
    10. */
    11.  
    12. public class BugExample : MonoBehaviour
    13. {
    14.     [SerializeField] private DerivedEventContainer container;
    15. }
    16.  
    17. [System.Serializable]
    18. public class DerivedEvent : UnityEvent<string> {}
    19.  
    20. public abstract class EventContainer<TEvent>
    21. {
    22.     [SerializeField] private TEvent derivedEventBug;
    23.  
    24.     [SerializeField] public TEvent derivedEventWorks;
    25. }
    26.  
    27. [System.Serializable]
    28. public class DerivedEventContainer : EventContainer<DerivedEvent>
    29. {
    30.     [SerializeField] private DerivedEvent derivedEventAlsoWorks;
    31. }
     
  16. Akira_Kido

    Akira_Kido

    Joined:
    Dec 20, 2015
    Posts:
    5
    FYI seems fixed in 2018.4.16f1 :D
     
  17. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    13
    This has regressed in 2019.3.3f1.
     
    MajorBulldozer likes this.
  18. jwlondon98

    jwlondon98

    Joined:
    Mar 27, 2015
    Posts:
    12
    Possible workaround:

    1) Change PlayerInput component's Behavior to "Send Messages"
    2) In your custom class that is attached to the same GameObject as the PlayerInput component, add "On" before each action's respective method and make sure to pass InputValue value as a parameter

    Ex:
    Action is called "Move". Custom class has a method with a header that looks like: public void OnMove(InputValue value)
     
    Last edited: Mar 18, 2020
  19. andrew_ES

    andrew_ES

    Joined:
    Apr 19, 2016
    Posts:
    20
  20. saltysquid

    saltysquid

    Joined:
    May 1, 2017
    Posts:
    41
    I ran across this same bug. Upgrading to 2020.1.0b4.3439 fixed it for me.
     
  21. skaughtx0r

    skaughtx0r

    Joined:
    Mar 9, 2014
    Posts:
    74
    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 <Missing FunctionName> and I can no longer assign Dynamic callback functions.

    Edit: Updating to 2018.4.20f1 seemed to fix the problem...
     
    Last edited: Apr 8, 2020
    andersemil likes this.
  22. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    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.
     
  23. ModernWestern

    ModernWestern

    Joined:
    Oct 22, 2017
    Posts:
    2
    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
     
  24. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    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
     
    Last edited: Jul 20, 2020
  25. timmccune

    timmccune

    Joined:
    Sep 27, 2018
    Posts:
    29
    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:

    Code (CSharp):
    1. public void SetDoorState(bool newState)
    2. {
    3.     NewState = newState;
    4.     m_animator.Setbool(m_IsOpenAnimBoolParam, newState);
    5. }
    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:
    Code (CSharp):
    1. [System.Serializable]
    2. public class DoorParams : UnityEvent<bool, bool>
    3. {
    4.   public bool NewState;
    5.   public bool PlayAudio;
    6. }
    7.  
    8. [SerializeField]  private DoorParams m_OnCompleted;
    9.  
    10. //..
    11. public void SetDoorState(bool newState, bool playAudio = true)
    12. {
    13. //..stuff
    14.   m_OnCompleted.Invoke(m_OnCompleted.NewState, m_OnCompleted.PlayAudio)
    15. }
    16. //..
    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:
    Code (CSharp):
    1. public void SetStateAudio(bool newState)
    2. {
    3.   SetDoorState(newState, true);
    4. }
    5.  
    6. public void SetStateNoAudio(bool newState)
    7. {
    8.   SetDoorState(NewState, false);
    9. }
    10.  
    11. private void SetDoorState(bool newState, bool playAudio)
    12. {
    13. //..stuff
    14. }
    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.
     
  26. gakuhiro

    gakuhiro

    Joined:
    Dec 18, 2019
    Posts:
    3
    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?
     
  27. sdb7

    sdb7

    Joined:
    Apr 8, 2013
    Posts:
    23
    Fixed on 2019.4.8f1 LTS

    upload_2020-8-25_11-14-10.png
     
  28. HgGamer

    HgGamer

    Joined:
    Jul 11, 2014
    Posts:
    1
    Same issue on 2019.4.14f1
     
    Marks4 and FusedShadow like this.
  29. slip777sg

    slip777sg

    Joined:
    Apr 20, 2020
    Posts:
    1
    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 <YourScene>.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.
     
  30. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    Same problem on Unity 2019.4.26f1...
     
    Last edited: May 18, 2021
  31. duckSPLASH

    duckSPLASH

    Joined:
    Jul 11, 2020
    Posts:
    14
    Same problem in 2021.1.6f1

    Only started when I started using text mesh pro.
     
  32. okaybj

    okaybj

    Joined:
    Nov 15, 2018
    Posts:
    33
    public UnityEvent<string, string> OnChatMessage;

    isn't showing up in the inspector.. im using 2019.4.22f1. TMPro is in my project
     
  33. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    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.
     
    Last edited: Jun 16, 2021
    Keita-kun likes this.
  34. serphon

    serphon

    Joined:
    Apr 25, 2018
    Posts:
    1
  35. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    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.
     
  36. Gretsok

    Gretsok

    Joined:
    Mar 20, 2020
    Posts:
    4
  37. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi can you post the part of the code you are using to expose the event in the editor?
     
  38. Zaddo

    Zaddo

    Joined:
    May 19, 2012
    Posts:
    78
    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<xxx> 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.
     
    Last edited: Jun 18, 2022
  39. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    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?

     
  40. timmccune

    timmccune

    Joined:
    Sep 27, 2018
    Posts:
    29
    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.
     
  41. Alixar

    Alixar

    Joined:
    Mar 13, 2019
    Posts:
    50
    Still happening in 2021.3.18.
    Anyone knows a workaround?

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.Events;
    4.  
    5. [System.Serializable]
    6. public class PlantTreeEvent : UnityEvent<int>
    7. {
    8.  
    9. }
    10.  
    11. [System.Serializable]
    12. public class RemoveTreeEvent : UnityEvent<int, Guid>
    13. {
    14.  
    15. }
    16.  
    17. public class PlantTree : MonoBehaviour
    18. {
    19.     [SerializeField] PlantTreeEvent plantTree = null;
    20.     [SerializeField] RemoveTreeEvent removeTree = null;
    21.  
    22.     void Start() {
    23.         if (plantTree == null) {
    24.             plantTree = new PlantTreeEvent();
    25.         }
    26.  
    27.         if (removeTree == null) {
    28.             removeTree = new RemoveTreeEvent();
    29.         }
    30.  
    31.         plantTree.AddListener(PlantTreeAction);
    32.         removeTree.AddListener(RemoveTreeAction);
    33.     }
    34.  
    35.  
    36.     public void PlantTreeAction(int world) {
    37.          Debug.Log("PlantTreeAction");
    38.     }
    39.  
    40.     public void RemoveTreeAction(int world, Guid guid) {
    41.         Debug.Log("RemoveTreeAction");
    42.     }
    43. }
    44.  
    upload_2023-2-9_18-7-11.png
     
  42. SulaimanWar

    SulaimanWar

    Joined:
    Dec 13, 2012
    Posts:
    12
    Answering this thread in case you're a frustrated individual like me who came across this only for people to echo that they're having an issue with little suggestions or solutions

    So I found from here that due to the way Unity serializes, you cannot have the script you're calling your method from and the script the UnityEvent on the same gameobject. So try to simply move your script to a separate gameobject. This worked for me
     
    DevHiatus and Alixar like this.
  43. AndreiMoraru123

    AndreiMoraru123

    Joined:
    Sep 16, 2023
    Posts:
    1
    If this helps anyone, my method was private. Switching to public made the dynamic callback show up.
     
  44. RohanP

    RohanP

    Joined:
    Jun 15, 2020
    Posts:
    1
    In my case the method signature of the method i wanted to add via the inspector did not match the method signature required and so it did not show up. Fixing the method signature resolved the issue for me