Custom mouse cursor resets after calling RemoveAllViewportWidgets()

I’ve set the custom mouse cursors in the project settings. They are working fine, but when I call RemoveAllViewportWidgets() all the cursors resets to the OS defaults.

Is there any way to preserve them or reset manually after new level loads?

Is this when playing, or just opening a level in the editor?

If while playing, try calling the function or setting the variables under gameinstance, as gameinstance is the only thing that persists between level changes(when playing, not when changing levels in the editor).

This happens every time new level is loaded at runtime. If I just change the level in the editor and then enter play mode, the cursor will have the custom icon, but on next level switch it will disappear again.

About gameinstance: I’m setting the cursor in the project setting in the editor, and I don’t know if there is a way to do this frome code. It would defenitely solve the problem if I could find the function for this, but no luck so far.

Hello Elringus,

Are you setting show mouse cursor to true inside of your level blueprint? If this is the case, the mouse is disappearing because it has not been told to show up in the other level. Try setting your mouse cursor to show up from within the player character on begin play. I hope this information helps.

Make it a great day

Hello Rudy,

Thanks for the answer, but it have nothing to do with my problem. The cursor is not disappearing (I didn’t even mention this in the question). I’m talking about custom cursor icon (graphics/widget) wich is set in the project settings (Project Settings → Engine → User Interface) being reset to default OS on level change.

Hello Elringus,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Is the screen shot provided in your previous post your current set up in your project?
  2. Are you making any other modifications to your cursor anywhere else in the project?
  3. If so, could you provide screen shots of any blueprints that may be involved with this issue?
  4. Can you reproduce this issue in a clean project?
  1. Yes;
  2. Not really, I’m just setting the bShowMouseCursor = true in the player controller;
  3. I’m not using BP at all in the project;
  4. Here is a clean repro project: GitHub - Elringus/UECursorBug: Bug with cursor widget being reset on level change Just press LMB to load other level and the cursor widget will reset to OS default.

While preparing repro project, I noticed that this bug happens when I call RemoveAllViewportWidgets() (I need to remove all the widgets before I change levels).

Most likely, it happens due to this line: https://github.com/EpicGames/UnrealEngine/blob/8a80b5541f69a79abf5855668f39e1d643717600/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp#L1945

Looks like this method adds cursors: https://github.com/EpicGames/UnrealEngine/blob/8a80b5541f69a79abf5855668f39e1d643717600/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp#L611

I’ve wanted to call it manually after RemoveAllViewportWidgets() to restore my cursors, but unfortunately it is private :frowning:

Could you please suggest a workaround for the problem while this bug being fixed? I really don’t want to change the sources, as I’m working with a dist version of the engine.

While this bug being fixed, I’ve found a solution: just use an iterator over UUserWidget to remove all the added widgets one by one, without calling the RemoveAllViewportWidgets() method. The cursors won’t be affected this way.

Hello Elringus,

If you are removing all widgets from the viewport to prevent them from showing up in the next level this is no longer needed in 4.8. All widgets are removed when changing levels by default (The custom cursor will NOT be removed). If there is another reason for removing the widgets from the viewport before changing levels I have another solution for you. The Example is below. I hope that this information helps. This worked for me on my end.

Get all Widgets of Class (UserWidget) > For Each Loop > Array element == Custom Cursor Widget > If equal to > Do nothing> Else > Remove from viewport > Loop Complete > Open Level

Example in Blueprints:

Make it a great day

2 Likes

Oh, I didn’t know that they are now removed automatically on level change. This completely solves my problem :slight_smile: Thank you!

Rudy’s solution worked great for my project, as we’re using level streaming (doesn’t delete all widgets on loading level) and RemoveAllWidgets knocked out our custom cursor. Thank you!

Nonetheless, the RemoveAllWidget is a valid tool to use, but if it breaks the custom mouse cursor, that’s bad.

This solution no longer works; RemoveFromParent is apparently not enough to satisfy OpenLevel.
(currently still in 4.13)

I wrote a report and submitted it to the developers for further consideration. I have provided a link to the public tracker. Please feel free to use the link provided for future updates.

Link: Unreal Engine Issues and Bug Tracker (UE-39429)

Make it a great day

Nice catch, we’ve had problems with this a long time but never put it on priority. This will problay solve it for us aswell, big thanks!