UWidgetComponent::GetUserWidgetObject() LNK error.
I'm getting a link error when trying to access the UserWidget object tied to my WidgetComponent.
**Error 14 error LNK2019: unresolved external symbol "public: class UUserWidget __cdecl UWidgetComponent::GetUserWidgetObject(void)const " (?GetUserWidgetObject@UWidgetComponent@@QEBAPEAVUUserWidget@@XZ) referenced in function "public: virtual void __cdecl UWD_CameraTrace::TickComponent(float,enum ELevelTick,struct FActorComponentTickFunction )" (?TickComponent@UWD_CameraTrace@@UEAAXMW4ELevelTick@@PEAUFActorComponentTickFunction@@@Z) C:\Users\Austin\Documents\Unreal Projects\WD_Torture\Intermediate\ProjectFiles\WD_CameraTrace.cpp.obj WD_Torture*
I'm not too sure as to why I'm getting the error. I've been searching for a couple of hours now, and I've come up with nothing. Hopefully someone can help!?!?
Thanks a bunch, all.
asked Jan 20 '15 at 11:43 PM in C++ Programming
The functions in WidgetComponent aren't exported in a way that other modules can communicate with them.
If you were to look at WidgetComponent.h, somewhere in the UCLASS metadata it will read MinimalAPI, which doesn't export the symbols, hence "unresolved external symbol" when you're trying to call GetUserWidgetObject();
By removing that MinimalAPI metadata and adding the module API prefix to the class declaration line in the header:
You can export every function so that they can be accessed by other modules (such as your gameplay module).
This does involve making a change to the UE4 source code though, unless they decide to export the symbols by default in future.
In order to pull those headers in from your external module (UMG), open your Project.Build.cs file in your game module folder, and on the PublicDependancyModuleNames line, add the UMG module, which is from the UMG folder name. Here's mine:
Then in the class you're working in #include "WidgetComponent.h" and "UserWidget.h", or an extended version of that class.
Also found this: "Functions and classes that need to be accessed outside of their module must be exposed via the *_API macros. Each item that is exposed comes with a compile-time cost, so be sure to only expose what is needed. If you only need access to a single function in a class, exposing just that function instead of the class can save a significant amount of time when compiling."
Also be aware that somewhere along the way, this process has borked my hot reload, and the unresolved external symbol error will keep happening unless you recompile with the editor closed and make sure it's been closed for long enough that the editor is no longer in memory and hot reload doesn't still fire.
I've gotten as far as getting my own traces to hit the widgetcomponent, pick up the widgets (such as a text box) using some maths, but I'm lacking the final part of the puzzle, which is setting the focus to the WidgetComponent and the textbox inside it so I can type on it. The default behaviour of widgetcomponent isn't quite what I'm looking for, but this is a story for another answers post I think. Hope this helps!
answered Jan 27 '15 at 02:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here