x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I override OnMouseButton in C++

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... alt text alt text

Product Version: UE 4.12
Tags:
more ▼

asked Jul 07 '16 at 03:08 PM in C++ Programming

avatar image

Espii77
18 3 6 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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 Cloudy ;)

more ▼

answered Jul 07 '16 at 03:52 PM

avatar image

Cloudy McStrife
465 13 16 38

avatar image Espii77 Jul 07 '16 at 04:11 PM

I've updated the code to alt text

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

avatar image Cloudy McStrife Jul 07 '16 at 04:52 PM

Hey First try to write a "override" behind NativeOnMouseButtonDown(...) I don't think that's the problem but it's cooler :D

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 Cloudy

EDIT: Ok I just checked. You need "UMG" "Slate" and "SlateCore"

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Okay, thanks to Cloudy McStrife, i found the answer.. In {YourProjectName}.build.cs, you just uncomment the line

 PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
more ▼

answered Jul 07 '16 at 05:36 PM

avatar image

Espii77
18 3 6 7

avatar image Cloudy McStrife Jul 07 '16 at 05:56 PM

Glad to have helped you :) Just mark my answer as resolved so that everyone knows that this question was answered :)

Cheers

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 :).

alt text

sans titre.png (304.1 kB)
more ▼

answered Jul 07 '16 at 03:17 PM

avatar image

NymKappa
692 32 22 56

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question