Cant assign Generic inherited ScriptableObject in inspector after updating to 2020.1

Hey all, after updating to Unity2020 I’ve ran into a bit of a curious issues with my scriptableobject event system where I can’t assign my objects to inspector if the object is generic

First of here is my “main” code and base classes

[CreateAssetMenu( menuName = "Events/GameEvent" )]
public class GameEvent : ScriptableObject, IGameEvent
{
    private List<IGameEventListener> _listeners = new List<IGameEventListener>();
    [Button]
    public void Invoke()
    {
        for (int i = _listeners.Count - 1; i >= 0; i--)
        {
            _listeners[i].OnEventRaised();
        }
    }

    public void RegisterListener(IGameEventListener listener)
    {
        _listeners.Add(listener);
    }

    public void UnregisterListener(IGameEventListener listener)
    {
        _listeners.Remove(listener);
    }
}

public abstract class GameEvent<T> : GameEvent, IGameEvent<T>
{
    private List<IGameEventListener<T>> _listeners = new List<IGameEventListener<T>>();

    public void Invoke(T value)
    {
        for (int i = _listeners.Count - 1; i >= 0; i--)
        {
            _listeners[i].OnEventRaised(value);
        }
    }

    public void RegisterListener(IGameEventListener<T> listener)
    {
        _listeners.Add(listener);
    }

    public void UnregisterListener(IGameEventListener<T> listener)
    {
        _listeners.Remove(listener);
    }
}

Next I’ve inherited the generic game event like this so I can create specialized events with the specific type I wanna parse in the event:

[CreateAssetMenu(menuName = "Events/BoolGameEvent")]
public class BoolGameEvent : GameEvent<bool>
{
}

Now in a different script I’d add this so I can call .Invoke(), Please note this is not the full script but only the related part of it and there is NO errors on my projects:

public class PowerUp : MonoBehaviour
{
    [SerializeField]
    GameEvent _event;

 
    public void ExecutePowerUp()
    {
        if (_event != null)
        {
            if (_event is GameEvent<int> gei)
            {
                gei.Invoke(_targetEventValue);
            }
            else if (_event is GameEvent<bool> geb)
            {
                geb.Invoke(true);
            }
            else
            {
                _event.Invoke();
            }
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            ExecutePowerUp();
            Destroy(gameObject);
        }
    }
}

With all my code out of the way I now add my Powerup script to a gameobject:
6134936--669110--upload_2020-7-27_0-13-56.png

I’ve now also created a Scriptableobject of BoolGameEvent as an asset;
6134936--669113--upload_2020-7-27_0-16-23.png

But now if I open the the object picker from my powerupscript this event is nowhere to be found:

And if I try to drag and drop the script on to the script I get this error:
6134936--669119--upload_2020-7-27_0-18-54.png

All this seems to work fine in unity 2019.4(LTS) but stopped working in 2020

I’ve already tried the following to resolve my problem without luck:
Restart unity and VS
Reimport All
Delete the library folder
Rename The Generic GameEvent class
Put the Generic GameEvent class into its own file
Rename the generic GameEvent and put it into its own file
Recreate the ScriptableObject asset in 2020
Change the type of _event variable in my PowerUp Script to GameEvent
Changed GameEvent to inherit from ScriptableObject instead of GameEvent (and change related code to work with this change)
Changed SerializeField to SerializeReference (not sure if this is related to generic objects or only collections so had to try)

What seems to work is:
Open Unity 2019.4 and assign the GameEvents from there seems to work and be recognized in the 2020 version, but I’m still unable to change the GameEvent

Does anyone know what the cause of this could be and how I can fix it?

  • Thanks a lot in regard!

Still trying to look around for solutions but it seems that there is other “interesting” Generics variable issues in 2020, may have something to do with the new generic serializer?

I’ve gotten it to work after I’m created a new project and added all the old files to it as well as deleting all the events and recreating them, I guess something may have gone wrong in the upgrade of the project some how, but oh well I’m back up and running for now at least

I’m having this issue as well; I have a base class SettingsItem that is inherited by SettingsWeapon and SettingsMagazine; I can assign SettingsWeapon and SettingsMagazine fine to gameobject scripts that take the SettingsItem format, but not to the base class. Peculiar indeed.

I know that this post is a little bit expired, but maybe nowadays someone struggle with the same problem. For sure you have to keep every scriptable object script in another cs file. Other way you cannot apply scriptable object to serialized field.

I got around working with “Scriptable Objects architecture” and Got stuck with the same problem. Have a base for Weapons and some other classes ( MeleaWeapon, GunWeapon, and more ) inherited from it.

Can’t assign any of them to List … inside scriptableobject.

Are they just not showing up in the object picker, or can you not drag and drop them into object fields?

The Unity object picker can be pretty bad at showing valid options to pick, though you can still drag-and-drop valid types into the inspector.