Search Unity

Question unity_InstanceID undefined

Discussion in 'Shader Graph' started by AG_in_person, May 28, 2023.

  1. AG_in_person

    AG_in_person

    Joined:
    Jul 3, 2018
    Posts:
    5
    Hello.

    I'm trying to get procedural instancing to work in shader graph. As far as I can tell, I followed this approach:
    https://forum.unity.com/threads/drawmeshinstancedindirect-and-shader-graph.720638/
    https://answers.unity.com/questions/1877154/urp-shader-graphs-with-instanced-indirect-instance.html

    However, the graph doesn't compile because I use
    unity_InstanceID
    (as given in the referenced answers). It keeps being undefined. (
    undeclared identifier 'unity_InstanceID' at ...
    ).

    I know from the sources that this variable willbe defined ifa couple of conditions are met, having
    PROCEDURAL_INSTANCING_ON
    amongst others. It is even described here:
    https://gist.github.com/Cyanilux/4046e7bf3725b8f64761bf6cf54a16eb

    Nevertheless, I did't succeed in getting it to work.
    Can someone point me to more secret documentation, or otherwise help me out?
    Thank you!
     
  2. AG_in_person

    AG_in_person

    Joined:
    Jul 3, 2018
    Posts:
    5
    Solution:
    In "Graph Inspector", I had to remove the leading underscore in field "Reference" from
    _PROCEDURAL_INSTANCING_ON
    (which was generated when adding the keyword) to the name of the keyword. Then, I inspected the generated code and saw that, for the very first time, I was on the right track regarding the preprocessor definitions. Subsequently, the compiler error mentioned in the original post was resolved.

    EDITED: Moved new issue to new thread.
     
    Last edited: May 31, 2023