Why I'm getting "Accesed None..." error when trying to add widget to viewport?

Hello. I created a widget and added it to viewport but sometime when I’m going through my levels I’m getting an error “Blueprint Runtime Error: “Accessed None trying to read property CallFunc_Create_ReturnValue”. Node: Add to Viewport Graph: EventGraph Function: Execute Ubergraph BP Top Down Character Blueprint: BP_TopDownCharacter”. I can’t even know where is problem, because I see widget every time (so it exist). I suppose ue is trying to get widget when it’s not existing, but even with additional logic the error is appearing sometime.
Here’s my BP of Top Down Character:


How to prevent this error? Maybe I should create widget in somewhere else or maybe override any event?

I would personally keep the UI in a blueprint derived from the HUD class & set this specific hud in the game mode.

Then if needed you can always access it through GetPlayerController => get HUD (cast to your hud bp) and then the specific widget variable (promote to variable after creating the widget)

Do you mean I just should relocate it to game mode blueprint?

  1. Create a new blueprint based on HUD
  2. inside this blueprint on begin play spawn your widget and set it to a variable then add to viewport
  3. Create custom game mode BP
  4. set the HUD in game mode BP to the blueprint created in pt. 1
1 Like

In 2. when you saing “spawn” you mean create widget or exactly spawn as actor from class?

In 2 Create widget

Thank you! I tried to start my game 10 times and haven’t seen that error.