[Solved]Game crashes showing a user widget when key is pressed.

Hi, i’ve been learning UE4 for the past month, i have been following some tutorials made with BP but since i have experience with C++ i prefer to use it, so i’ve been trying to translate the things i find with BP into C++.

I’m using a User Widget BP to show a menu with some texts and button properties binded to properties in my player character. The widget was created directly from User Widget BP, and i have a reference to it in my player character. Now i have an input bind in my player character that checks if the widget is in viewport then it removes it from viewport, and if it is not it adds it to viewport.
But sometimes when i try to make it show it crashes. At first i thought it was when a property in the player, read by the widget changed, but then i found it can crash without changing anything if i open and close it several times, it happens more often when my character is performing other actions.

The crash report says it is causing an access violation exception, and the exception stack trace seems to indicate the origina is the Execute() method for the input delegate, i’m not sure how the input component works but it sounds to me like the delegate is somehow missing.

An interesting detail is that while trying to check for nulls in my delegate function the game still crashes but i sometimes got a different error, instead of access violation i get an assert failure and it points to a line in my function where i perform a cast from AController to APlayerController, i don’t know if both crashes are related or they are 2 different problems, but i can’t identify the root of any of those crashes. I wonder if anyone has any idea what is happening. I’ll post a ss of the regular crash and the parts of my code involved, and i’ll try to get the assert error again to add it.
Thanks in advance for any help.

Please tell me how you solved this issue. I’m having the same problem.
Edit: Nevermind, I managed to solve this by running the function on an async game thread.