Search Unity

Use "Integer" data type in Unity shader properties causes compile error.

Discussion in 'Shaders' started by 949078, May 25, 2022.

  1. 949078

    949078

    Joined:
    Jan 10, 2019
    Posts:
    1
    upload_2022-5-25_15-36-13.png

    The data type in the properties of the shader described in the unity documentation can use "Integer" to represent a real integer. But when I use "Integer" in the shader, I get a syntax error. "Int" can be used correctly, but the type is baked into a float and I need a real integer. The shader code is as follows:

    Shader "Custom/NewUnlitShader"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    _ExampleName ("Integer display name", Integer) = 1
    }
    SubShader
    {
    ........
    }
    }
    upload_2022-5-25_15-38-2.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    What version of Unity are you using, because this was a feature that was added in 2021.1. If you're using a 2020 or 2019 version of Unity it won't work because the option doesn't yet exist.
     
    Darkgaze likes this.
  3. swishchee

    swishchee

    Joined:
    Jul 23, 2020
    Posts:
    63
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    @swishchee unrecognized by what exactly? From the screenshot it looks like it's not recognized by the syntax highlighting in your editor.
     
    swishchee likes this.
  5. swishchee

    swishchee

    Joined:
    Jul 23, 2020
    Posts:
    63
    Ah ha, you're right! I initially chose to ignore the error in the IDE (Rider), but then I proceeded to get some unrelated type definition errors that I THOUGHT may have been attributed to this unrecognized type. It turns out, however, that the type error I was getting had to do with redefinitions in different passes. However, I'm getting another error that I'll make a new post about, because I am unsure of how to address it, and it's definitely not related to this. I managed to get this code to work just fine without any unity errors, except for the one that's fundamentally related to the Metal API.