Linker errors when modifying RenderResource

RESOLVED

RenderResource.h notes the solution via this comment:

/**
 * NOTE - Adding new virtual methods to this class may require stubs added to FViewport/FDummyViewport, otherwise certain modules may have link errors
 */

The files you need to add stubs to are:

  • UnrealClient.h
  • SceneViewport.h

(I would post this solution as an answer but my question has not been approved by a moderator yet.)


ORIGINAL POST

I declared and defined a public virtual function in a class but I’m receiving a linker error which states that the linker cannot find the definition of this function.

Here is where I declare and define the function:

virtual void InitRHI_ALLOW_UNORDERED_ACCESS() {}

Here is the error:

Error	LNK2001	unresolved external symbol "public: virtual void __cdecl FRenderResource::InitRHI_ALLOW_UNORDERED_ACCESS(void)" (?InitRHI_ALLOW_UNORDERED_ACCESS@FRenderResource@@UEAAXXZ)	UE4	<PATH>\Engine\Intermediate\ProjectFiles\Module.DistCurveEditor.cpp.obj	1

More context:

I’m modifying Engine\Source\Runtime\RenderCore\Public\RenderResource.h to add a second version of InitRHI() that allows a UAV to be created for a resource. I followed what InitRHI() does and how it’s called, but my addition is leading to the error above. I cleaned the project files with Visual Studio in case an old .obj was being used, but the error has persisted.

InitRHI() is declared and defined in the same way:

virtual void InitRHI() {}

Perhaps this is a general question that belongs on StackOverflow but the context of modifying Unreal Engine source code seems important. For example, Module.DistCurveEditor.cpp.obj could be a clue.

Here are all the files with the same linker error:

  • Module.DistCurveEditor.cpp.obj
  • Module.FontEditor.cpp.obj
  • Module.Cascade.cpp.obj
  • Module.MediaFrameworkUtilitiesEditor.cpp.obj
  • Module.DetailCustomizations.1_of_4.cpp.obj

Three out of the five files contain the string “Editor”.

None of the source corresponding to these object files were modified directly, and the purpose of creating a new InitRHI function was to avoid affecting any other part of the engine. The engine calls InitRHI by default and doesn’t know about my new function, except for a tiny custom area. This tiny custom area is only called by project-level code, not engine-level code.

CLUE: In comments of RenderResource.h: “NOTE - Adding new virtual methods to this class may require stubs added to FViewport/FDummyViewport, otherwise certain modules may have link errors”

The two files that need stubs are:

  1. UnrealClient.h
  2. SceneViewport.h

Or you can CTRL+F across the engine source for “linker errors with FRenderResource”

RenderResource.h notes the solution via this comment:

/**
 * NOTE - Adding new virtual methods to this class may require stubs added to FViewport/FDummyViewport, otherwise certain modules may have link errors
 */

The files you need to add stubs to are:

  • UnrealClient.h
  • SceneViewport.h
1 Like