Crash when using a slate widget with GetPlayerController

I have a widget which in one of the bound functions calls GetPlayerController. I have previously had this HUD added to the screen (which worked) but I tried adding it to a WidgetComponent. As soon as I do this, the editor crashes:

Access violation inside UGameplayStatics::GetPlayerController on line 38 (presumably now world [or no WorldContextObject])

This question seem related, but haven’t been resolved:

Crash when spawning Actor with WidgetComponent

Hello ,

I was unable to reproduce this issue on our end. I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. What version of the engine are you using?
  2. Can you reproduce this in a clean project?
  3. If so, could you provide a detailed list of steps to reproduce this issue on our end?
  4. Can you clarify to what actor it is that you are adding a widget comment to?
  1. 4.6
  2. Yes (for once!)
  3. Steps:
  • New project, create an actor blueprint and a blueprint widget
  • In widget, add a text field and bind a function to it
  • In the bound function call something like GetPlayerController() and call GetDisplayName on that and return that from the bound function
  • Add a WidgetComponent to the actor
  • Set the widget class to be the BP widget just created
  • Observe the crash
  1. The actor is just an empty blueprint deriving from Actor with the WidgetComponent in it.

Hello ,

I was able to reproduce this issue on our end in 4.6. However, after running the same test in 4.7.2 I have found that this issue has been fixed. Thank you for your time and information.

Make it a great day

Could you point me towards a commit that fixes it so I can integrate that in to our engine (we are not currently looking to upgrade to 4.7)

Hello ,

I believe that this is the commit that you would be looking for. I hope that this helps.

https://github.com/EpicGames/UnrealEngine/commit/48d435dfd39971d3c6f4f4c254551f8e93aac403

Make it a great day