Custom Node using struct function has error which "External function used in non-library profile"

I have one custom node.
My .ush & .usf in here

.ush

#ifndef __CARDSHADER_USH__

#define __CARDSHADER_USH__

struct RenderFunc

{

    float2 ParallaxMapping(float2 uv,float3 viewDir,float heightScale);

    float4 FinalRender();

};

#endif

.usf

#include "CardShader.ush"




float2 RenderFunc::ParallaxMapping(float2 uv,float3 viewDir,float heightScale) {

    float2 offset = viewDir.xy / viewDir.z;

    offset = offset * heightScale;

    return uv - offset;

}




float4 RenderFunc::Output() {

    float4 BackColor = Texture2DSample(_Back,_BackSampler, ParallaxMapping(_uv, _ViewDirWs, 0.2));

    float4 BackgroundColor = Texture2DSample(_Background, _BackgroundSampler, ParallaxMapping(_uv, _ViewDirWs, 0.4));

    float4 FrontColor = Texture2DSample(_Front, _FrontSampler, ParallaxMapping(_uv, _ViewDirWs, 0.6));

    float4 BorderColor = Texture2DSample(_Border, _BorderSampler, ParallaxMapping(_uv, _ViewDirWs, 0.7));




    float4 finalCol = float4(0,0,0,1);

    finalCol = BackgroundColor;

    finalCol = lerp(finalCol, FrontColor, FrontColor.a);

    finalCol += BorderColor;

    return finalCol;

}

custom node



 "/Shaders/CardShader.ush"

RenderFunc _func;
_func.FinalRender();

return 0;

Output:
[SM6] Shader debug info dumped to: “D:\qsw\GameWorkSpace\UE\RTR_Learning\Saved\ShaderDebugInfo\PCD3D_SM6\M_CardMat_61540b8bec78582b\Default\FLocalVertexFactory\FLumenCardPS\0”

D:\UE_5.8\Engine\Shaders\Private\MaterialTemplate.ush(3749,7): Shader FLumenCardPS, Permutation 0, VF FLocalVertexFactory:
/Engine/Generated/Material.ush:3749:7: note: used here
_func.FinalRender();
^
error: External function used in non-library profile: \01?FinalRender@RenderFunc@?1??CustomExpression0@@YA?AV?$vector@M$03@@UFMaterialPixelParameters@@V?$Texture2D@V?$vector@M$03@@@@USamplerState@@121212V?$vector@M$01@@V?$vector@M$02@@@Z@QAA?AV3@XZ

I don’t know how to resolve it really.
Please me!

found it, your names do not match. the struct declares ParallaxMapping and FinalRender, but you only define ParallaxMapping and Output. FinalRender is never defined anywhere, so the compiler treats it as an external unresolved function, which is exactly what the non-library profile error is telling you: it cannot link a body for it. either rename Output to FinalRender or change the custom node to call _func.Output().

while you are in there, two simplifications that avoid this class of problem entirely:

  • skip the struct. custom nodes work best with plain free functions in the .ush: float2 ParallaxMapping(…) and float4 FinalRender(…), called directly. struct member functions add nothing here and are the part that generated the confusing error.
    • you do not need the .usf wrapper at all. a Custom node with an Include File path to the .ush plus the function calls in the code field is enough; the .usf indirection only matters for virtual material functions.
  • also double check the include path style: /Project/… for files in your project Shader directory or /Engine/… for engine ones, and that the .ush is under a folder the shader compiler watches (Shaders folder next to Source, or Content/Shaders with the virtual path set up).