Linker error 2019: unresolved external symbol when using existing shaders from source code as variables

Hello guys,

I would like your help. I have an unreal engine class in which I wanna use already existing shaders as variables from engine source code. So for example we have these lines of code:

TShaderRef FSlateMaterialShaderVS VertexShader;
TShaderRef FSlateMaterialShaderPS PixelShader;

VertexShader->SetViewProjection(projection);
VertexShader->SetMaterialShaderParameters(parameters);

PixelShader->SetParameters(parameters);

The problem is that my crash log displays that message:
error LNK2019: unresolved external symbol "public: void __cdecl FSlateMaterialShaderVS::SetViewProjection

error LNK2019: unresolved external symbol "public: void __cdecl FSlateMaterialShaderVS::SetMaterialShaderParameters

error LNK2019: unresolved external symbol "public: void __cdecl FSlateMaterialShaderPS::SetParameters

which are linker errors and I know most of the times these errors fix by including the class classname keyword at the top of your class or by including the correct module in the build.cs file. Neither of those solutions fixed the problem. just to be more specific, when I just declare the shader variables, it does not throw the errors. When I call one of their functions then I have these linker errors.

Anyone who could help me please?

Thanks,
Panos

The code you are using is in the SlateRHIRenderer module, so add it as a dependency in your *.build.cs file.

e.g.

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "SlateRHIRenderer" });

already done that, it did not work :confused:

OK errors solved. The problem was that the header file of the shaders I wanted to use is in private folder so it cannot be used. The solution is, I created a custom class and copied the source code I needed and used different class names. So for anyone out there deals with the same errors, check first what visibility the header file has. if it is in a private folder the only solution is to create a custom class with the same code.