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?
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:
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
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
Oh, I didn’t know that they are now removed automatically on level change. This completely solves my problem 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!