Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    12
    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.
     
  7. JFortunato

    JFortunato

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

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    5
    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,559
    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:
    2
    This seems to be an issue with 2018.4.9f1 as well...
     
  12. petersvp

    petersvp

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

    Attached Files:

    bramble-operations likes this.
  13. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,045
    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:
    24
    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:
    2
    FYI seems fixed in 2018.4.16f1 :D
     
  17. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    12
    This has regressed in 2019.3.3f1.
     
  18. jwlondon98

    jwlondon98

    Joined:
    Mar 27, 2015
    Posts:
    6
    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:
    8
  20. saltysquid

    saltysquid

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

    skaughtx0r

    Joined:
    Mar 9, 2014
    Posts:
    52
    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:
    62
    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:
    77
    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:
    10
    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:
    12
    Fixed on 2019.4.8f1 LTS

    upload_2020-8-25_11-14-10.png
     
unityunity