Search Unity

Bug Unable to set Custom Function file(12.0.0)

Discussion in 'Shader Graph' started by Dinamytes, Mar 21, 2021.

  1. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    Only Text Asset (.cs, .txt...) can be selected, which does not include the .cging and .hlsl files


    Unity 2021.2.0a9
     
  2. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    Reproducible in Unity 2021.2.0a10 that just released. Also reproducible when using all the latest packages as of the time of this writing from the Graphics repo on master branch and on sg/fix/1322467 branch (see link to PR below) which may be related

    @Dinamytes-Gabriel_Mota did you file a bug report yet?

    Worth noting that the problem seems to be that .hlsl and .cginc files are no longer imported as TextAsset, they are imported as a new type called ShaderInclude, but Shader Graph is still expecting the file to have been imported as TextAsset. But even forking simply changing the type in CustomFunctionNode.cs from TextAsset to ShaderInclude doesn't work, because ShaderInclude is a protected class, which as far as I know is part of the Unity Editor's internal codebase and cannot be (trivially) forked or modified by "users" aka software developers that don't work for Unity Technologies. If assets are being imported as ShaderInclude by default, you'd think this class would be public at least for Unity's own packages to access? but it's an Alpha, anyway, so it's not that unexpected. I'm sure it will get sorted out soon.

    upload_2021-3-24_20-23-38.png

    And while I can't find explicit evidence, it's possible that this open pull request ShaderGraph] [2021.2] Fix include ordering #3924 is related (sg/fix/1322467 branch.) Even if it is not, I'm not sure how it could ever pass a comprehensive suite of tests when the Custom Function Node's file association is broken in the the current alpha in what seems like all scenarios.. but maybe I'm missing something?:
    https://github.com/Unity-Technologies/Graphics/pull/3924

    one possible clue in the PR is
    Which may mean it's being tested against a build of the Unity Editor that imports .hlsl and .cginc files as TextAsset as before and not ShaderInclude like the released alpha Editor builds?

    heads up @ChrisTchou if you can shed any light on this --it would be much appreciated. Thanks! <3
     
    Last edited: Mar 25, 2021
    Dinamytes likes this.
  3. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    @landonth I didn't, never checked what was the right way to report bugs so I shared here, good research ;)
     
  4. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    It's pretty easy, you just select "Report a Bug..." from the help menu:
    upload_2021-3-25_22-2-26.png
    And fill out the form. I just submitted a bug report but I suggest that you submit a report as well, the issue will get prioritized and resolved more quickly if there are multiple reports as it strongly implies reproducibility and highlights importance. It's certainly not yet listed as a known issue in the release notes and I can't find any explicit mention of these breaking changes in the Unity Editor (the "ShaderInclude" class) on the Graphics repo either. More info on bug reporting here: https://unity3d.com/unity/qa/bug-reporting
     
    Last edited: Mar 26, 2021
  5. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    Unity fogbugz case 1324528
     
    Dinamytes likes this.
  6. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    Last edited: Apr 3, 2021
  7. noodlesxp

    noodlesxp

    Joined:
    Aug 10, 2014
    Posts:
    3
    @Dinamytes in the meantime, you can get around this by declaring a new class at the top of HlslFunctionView.cs

    Code (CSharp):
    1. ...
    2. using UnityEditor.UIElements;
    3. using UnityEditor.Graphing;
    4.  
    5. class ShaderInclude : UnityEngine.Object
    6. {
    7. }
    8.  
    9. namespace UnityEditor.ShaderGraph.Drawing
    10. {
    11.     [Serializable]
    12.     public enum HlslSourceType { File, String };
    13. ...
    Then you can swap all references from TextAsset to ShaderInclude in HlslFunctionView.cs & CustomFunctionNode.cs

    Finally, you can remove the cast to ShaderInclude from TryGetGUIDAndLocalFileIdentifier in HlslFunctionView.cs
    Code (CSharp):
    1. AssetDatabase.TryGetGUIDAndLocalFileIdentifier(s.newValue, out guidString, out localId);
    I can successfully compile a graph shader using a custom .hlsl file with this method. I have no doubt that there will be a proper fix soon.
     
    LooperVFX likes this.
  8. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    noodlesxp likes this.
  9. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    179
    Dinamytes and noodlesxp like this.