I want to override OnMouseButton on the UserWidget in C++, but I keep getting linker errors. What is the correct way o do this?
I will post how I defined it here…
I want to override OnMouseButton on the UserWidget in C++, but I keep getting linker errors. What is the correct way o do this?
I will post how I defined it here…
I keep getting linker errors
You need to show us which linker error, otherwise nobody will be able to help you.
For my C++ UUserWidget, I usually just call a C++ function from the widget blueprint, easy :).
Hey Espii.
You cannot override the OnMouseButtonDown Function itself.
But you can override:
virtual FReply NativeOnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent );
which is the C++ Implementation of OnMouseButtonDown.
You could also override OnMouseButtonDown_Implementation but this Function is now deprecated and NativeOnMouseButtonDown should be overriden instead
Good Luck
Greetings
I’ve updated the code to
and these are the linker errors I am getting.
Creating library C:\Users\Simon\Documents\Unreal Projects\MyProject2\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject2.lib and object C:\Users\Simon\Documents\Unreal Projects\MyProject2\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject2.exp
2>MyHUD.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: static class FReply __cdecl FReply::Handled(void)” (_imp?Handled@FReply@@SA?AV1@XZ) referenced in function “public: __cdecl FEventReply::FEventReply(bool)” (??0FEventReply@@QEAA@_N@Z)
2>MyHUD.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: static class FReply __cdecl FReply::Unhandled(void)” (_imp?Unhandled@FReply@@SA?AV1@XZ) referenced in function “public: __cdecl FEventReply::FEventReply(bool)” (??0FEventReply@@QEAA@_N@Z)
2>MyHUD.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl FReply::~FReply(void)” (_imp??1FReply@@QEAA@XZ) referenced in function “public: __cdecl FEventReply::FEventReply(bool)” (??0FEventReply@@QEAA@_N@Z)
2>MyHUD.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl FReply::FReply(class FReply &&)” (_imp??0FReply@@QEAA@$$QEAV0@@Z) referenced in function “public: __cdecl FEventReply::FEventReply(bool)” (??0FEventReply@@QEAA@_N@Z)
Also, I get this warning:
warning C4264: ‘FReply UUserWidget::NativeOnMouseButtonDown(const FGeometry &,const FPointerEvent &)’: no override available for virtual member function from base ‘UUserWidget’; function is hidden
Hey
First try to write a “override” behind NativeOnMouseButtonDown(…)
I don’t think that’s the problem but it’s cooler
Second:
I think you have to include “UMG” “Slate” “SlateCore” to your (ProjectName).Build.cs
This is mine for example:
using UnrealBuildTool;
public class ProjectName: ModuleRules
{
public ProjectName(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Paper2D", "UMG", "XmlParser" });
// Uncomment if you are using Slate UI
PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore", "HeadMountedDisplay", "SteamVR" });
}
}
Just uncomment the Private Section and you should do fine.
And add UMG (Don’t know if needed) to PublicDependencies
Greetings
EDIT:
Ok I just checked.
You need “UMG” “Slate” and “SlateCore”
Okay, thanks to McStrife, i found the answer…
In {YourProjectName}.build.cs, you just uncomment the line
PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
Glad to have helped you
Just mark my answer as resolved so that everyone knows that this question was answered
Cheers