[C++] mouse events not working in the world

hi, I’ve been working on a C++ project for the past six months or so (it uses some blueprints as object templates, but 100% of the logic uses C++)

The first three months were focused on “how it works”/logic, and the past three months I spent working on “how it looks”/UI. Last night I was finally ready to merge the ‘how it looks’ with the ‘how it works’, when I noticed that the mouse events when interacting with the 3-D world are not working anymore.

The mouse events UI related seem to be working fine. At first I thought that I may have forgotten to set the root of my various UI components to HitTestInvisible.

I checked each UI component very carefully, I even tried to hide them all and eventually I even removed all of them from viewport, but the mouse events in the world were still not working. I even tried to force the input mode to game only UWidgetBlueprintLibrary::SetInputMode_GameOnly(this); but to no avail…

For example, hover over 3-D objects was supposed to enable stencil, or clicking the left mouse button was supposed to make the character move, which used to work just fine before shifting my focus on UI few months ago.

As it happens, the UI design approach was meant to be pretty sophisticated, and it took a while to put it all together, during which I didn’t need to keep an eye on the “how it works” side of the project.

I hope that my assumption that completely removing any UI from the viewport would make the above work again, as they haven’t been touched at all in the past few months, is correct.

For example, the default function MoveToMouseCursor generated when the project was created from the top down template was working just fine three months ago, but now nothing happens

FHitResult Hit;
GetHitResultUnderCursor(ECC_Visibility, false, Hit);

if (Hit.bBlockingHit)
{
	// We hit something, move there
	SetNewMoveDestination(Hit.ImpactPoint);
}

or, the stencil related function, BeginCursorOver(UPrimitiveComponent* HitComp) used to work three months ago, but not anymore, no breakpoint is being triggered anymore during troubleshooting.

I do not get any error messages, nor warnings, everything compiles fine, is just the mouse not interacting properly with the world, the UI events appear to be working fine though.

Please let me know.

Thanks!

Hey fmaacmab-

The code snippet provided appears to be from the default player controller for the project, have you changed which player controller is being used by the game mode class? If that’s not the case, please add a debug line to this section of code to check that it’s being called properly.

if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Magenta, TEXT(""));
}

You can use this code and just add something to TEXT("") . You’ll also need to have an include statement for the Engine.h file for GEngine to compile properly. If you don’t see your message being printed during PIE then it sounds like the mouse input is not being at all. If so, it may be best if you could provide a copy of your project for me to test directly.

Additionally, what version of the engine was the project created in and has the project been upgraded through any versions? If so, does the input still work on the older engine versions?

Hey , thank you very much for your reply ! I’ll reply in the main thread

Hi ,

per your comments:

-Using version 4.14.3
I added GEngine->AddOnScreenDebugMessage to the pregenerated SetNewMoveDestination function in my custom player controller which is correctly assigned in the configuration file/game mode, with the following behavior, I don’t have visual cues so I’ll try to be as explicit as I can:

I’m using a custom level class and level streaming. When I transition from the char gen level to the first game map via load and unload stream levels commands, the mouse seems to be in some sort of unfocused state and if I click once to regain focus relative to the world, the debug message populates.
But only in that instance and only once, after that any subsequent clicks in the world generate no events whatsoever, because there is no debug message being displayed anymore.

-Using version 4.13.2 which I just reinstalled
when compiling the code in VS 2015 using 4.13 version of the engine, at some point I now get an exception thrown: " access violation 0x38" in the Array.h line 2143 being called from my custom level class when adding a delegate on the media player
LogoMediaPlayer->OnEndReached.AddDynamic(this, &ASP_Persistent::OnPlayEndLogo);

this error comes before the unreal engine editor even starts, so it never gets to the point where I can click the play button for PIE. Therefore I cannot confirm if the mouse events are working in this version 4.13.2. The same line that adds a delegate in the custom level class works fine in version 4.14.3. This custom level class was not implemented three months ago while developing using 4.13 engine version, so this is the first time when I became aware of the error described above

I think the project was created in 4.11 or 4.12 version, and I upgrade as new stable generally available versions come up, I don’t use preview versions, that’s why currently I’m using 4.14.3. The last version of the project that I know the mouse events worked as expected was using 4.13, but as I mentioned, I now get the compilation error related to the delegate when attempting to use 4.13.2 so I cannot confirm its current behavior.

If needed, you can find a copy of the project here: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

Thanks!

Hi fmaacmab. Are you trying to add mouse events through c++? If so, I can copy and paste my methods in, see if you’re missing anything.

I also had some struggle with getting mouse events to be received correctly.

I found that adding the following to the constructor of the class that I wanted to receive inputs on solved my issue:

this->SetCollisionEnabled(
    ECollisionEnabled::QueryOnly
);
this->SetCollisionResponseToChannel(
    ECollisionChannel::ECC_Visibility, 
    ECollisionResponse::ECR_Block
 );

Perhaps a full example of how I set mine up might help to ensure all steps I have taken are also present in your project:

void Example::PostInitializeComponents()
{
    // "this" represents the object where I want to register my mouse over triggers
	this->OnBeginCursorOver.AddUniqueDynamic(this, &Example::TriggerVolumeMouseOverOccured);
}

void Example::TriggerVolumeMouseOverOccured(UPrimitiveComponent* touchedComponent)
{
    // Put a breakpoint here
}

thank you Jimmy for your comment. I have an area transition class that is already implemented very closely to your example. But the issue still persists. One thing I noticed: hover over does not trigger a breakpoint, but interestingly enough clicking the left mouse button once triggers the hover over breakpoint once, the same behavior happens with mousedown button, although the mouse button is still being pressed, the hover over triggers only once. one of the far-fetched possible explanations I’m contemplating, as I’m out of more pertinent explanations :-), is that these mouse event issues may be somehow connected to the unreal engine config INI files, and something got broke during version upgrades, but of course I’m just grasping at straws…

Hi , any update? I still can’t find a solution for this issue. Thanks!

I have not been able to find the cause of the mouse control issue. You mentioned that it was working before merging your logic/UI. Do you have a copy of the project before UI was added and/or are you able to separate logic from UI? This should at least let us know if the UI itself has something to do with it.

thank you for your reply. I did some poke around and I found an earlier version of my project with the UI freshly added, and I was able to replicate the issue. By that I mean that removing the UI from the player controller, led to the mouse working just fine, and adding the UI to the player controller, the mouse stopped working. Please see the pictures for a better visual. I’m currently contemplating starting from scratch, because starting a fresh new project in 4.15 and after immediately adding the UI with its custom class the mouse was working fine without any issue. I’m hoping that individually migrating the code functions and classes would eventually lead to either narrow down to the bottom of the issue or it will just work. Thanks!!

Thank you for the additional information. When I set W UIMain Menu to none in the project you sent, the editor will crash on pie in the DA2UE4PlayerController.cpp file (line 1059). The crash is due to a null reference in the code so is unlikely related to the mouse issue, however if changing this setting for you resolves the issue, then it seems that something in the UI setup is causing the issue.

Thank you . I found an older archive where the main menu UI was freshly added. This older archive is useful to illustrate my issue because it does not have a lot of custom UI code intertwined with the project up on that point. Whereas the project you tested has three months worth of custom code all over the place in various degrees of interdependence. So let’s focus on the older archive. The older archive, the one that has a new main menu widget with a new simple custom C++ class exhibits the behavior illustrated in the pictures above. No errors, but the mouse has the unwanted behavior. The kicker is that I literally copy paste the main menu widget uasset with the simple custom C++ class into a brand-new fresh project, and everything works as expected, the mouse doesn’t misbehave. So I may have hit some sort of unexpected situation where code A works perfect, code B works perfect but code A + B doesn’t work. I don’t have an answer, but I’m still considering slowly migrating all the classes and the assets from the current nonfunctional project into a fresh new start from scratch 4.15 project, this way I’m hoping that I can identify the culprit more precisely. Thanks!