- edited description
Non static commands on generic classes crash Unity
public class Test<T>
{
[Command]
private void Command() { }
}
Attempting to invoke Command
crashes Unity on 2021.1
I’m not sure what the best way to actually support this case is. Maybe just explicitly reject them during command loading instead of allowing them to load and then later crash? Could be done for now anyway
Comments (6)
-
reporter -
Personally I'm not a big fan of non static use of these types of attributes, due mostly to the fact that I don’t know what is happening to the object instance needed to be created. I’d vote for explicit rejection.
-
reporter I need to do more testing but I think the bug might happen for static commands too, I believe the issue is that it tries to invoke a command on an incomplete type (since the class is generic)
In general the object instance used for non static commands is controlled by the MonoTargetType
-
Ah, misread that, yeah that would be weird, but on the generic side I would also call it can be rejected. It’s overall an odd case I guess
-
reporter Tested on Unity 2018.4 and it doesn’t crash the editor (2021.1 is so unstable) but static commands also don’t work:
Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
So we could either completely reject this use case, or we could look into “forwarding“ the generic arguments of the class to the function. Normally a generic function would create a generic command like so
public class Generic { [Command("crash")] public static bool Command<T2>() => true; } becomes crash<T2>
We could make it so that generic arguments of the declaring type also make their way into the command
public class Generic<T1> { [Command("crash")] public static bool Command<T2>() => true; } becomes crash<T1, T2>
-
reporter - changed status to resolved
This is now supported in V2.4.6
- Log in to comment