Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Some questions about auto-generated c# class

Discussion in 'Input System' started by ConfusedCactus, Aug 2, 2020.

  1. ConfusedCactus

    ConfusedCactus

    Joined:
    Jul 3, 2018
    Posts:
    15
    I created a input action titled "PlayerControl" and pressed auto-generated c#class.

    So you will see a class like:

    public @PlayerControl()
    {
    }

    1) I am just wonder why there is a @ in front of the class name and what is its function?

    Also you have this function:

     public InputBinding? bindingMask
    {
    get => asset.bindingMask;
    set => asset.bindingMask = value;
    }

    2) Just wonder what does this bit "InputBinding? bindingMask" mean?

    Many thanks for answering!
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,387
    It protects against compilation failing if C# reserved words are used for names (e.g. "return"). The code could check whether the identifier is indeed a reserved word and only use @ then. The current code just always appends the @.

    The ? is for a "nullable" type. InputBinding is a struct so it's not possible to tell the difference between a default-initialized value (
    default(InputBinding)
    ) and a value that has not been set. Thus the "nullable" thing. The default value is
    null
    and thus different from
    default(InputBinding)
    so it's possible to tell a mask that hasn't been set to one that has been set to default values.
     
    ConfusedCactus likes this.
unityunity