sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.08k stars 1.11k forks source link

Exception in Code generation when using Generic Types in a Component #972

Open mhm90 opened 3 years ago

mhm90 commented 3 years ago

Hi,

I found a bug when the Code Generator tries to create corresponding functionalities of a component which uses a generic type parameter. Here is my components:

using Entitas;

public interface ITaskComponent : IComponent {}
public interface ITaskDataComponent : IComponent {}

[DontGenerate(false)]
public class OperationalTaskComponent<T> : ITaskComponent where T : class, ITaskDataComponent
{
    public long startTick;
    public long endTick;
    public float progress;
    public float activeRate;
    public T taskData;
}

public class SomeTask : OperationalTaskComponent<SomeTaskData> {}

As you can see in the above code, I have used DontGenerate attribute in order to avoid code generation for this class, but when I hit the Generate menu, it says: Argument cannot be null. Parameter name: key

At first, it was not clear for me that the cause of the error is lied behind this Generic Component super class thing, but after some investigation I found out that the problem happens in ToCompilableString method of DesperateDevs.Utils.SerializationTypeExtension where the Generic type is being processed. I think you should have some error logging and avoid using catch (Exception) with no logs.

Anyway, can you guide me how to use some hierarchical structure like this in my codes?

Cheers