Non static commands on generic classes crash Unity

Issue #150 resolved
Yusuf Ismail repo owner created an issue
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)

  1. Jakub Słaby

    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.

  2. Yusuf Ismail 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

  3. Jakub Słaby

    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

  4. Yusuf Ismail 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>
    

  5. Log in to comment