Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Exception in Code generation when using Generic Types in a Component

Open mhm90 opened this issue 3 years ago • 0 comments

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

mhm90 avatar Feb 14 '21 00:02 mhm90