User Widget Object is null

Hey everyone,

I have a widget component attached to a VR character. This is the HUD. The HUD has a compass on it that needs to update like in Skyrim or most other open world games. So, to call the function in the widget, I an getting the user widget object from the component, then casting it to the specific widget class. This has always worked before. After a lot of troubleshooting, I have figured out that the Get User Widget Object node is returning null. Any ideas why?

In you widget component (on the character) have you set the Widget Class or is it set to none?

Also where are you calling this? is it on the widget pre construct, construct function, or tick? (I’m guessing it’s from with a widget)

The Widget Class is correct. I’ve also tried a couple other classes to ensure that it is not the class itself causing this problem. No class works, but it is set to the correct class.

I am trying to access this widget from an actor component, within my own function. It is not in any construct or tick functions

I am trying to access this widget from an actor component, within my own function. It is not in any construct or tick functions

When? Begin play? And how? What component? Belonging to whom? Could you elaborate?



It it’s supposed to just show north east south and west then maybe just put the compass rotation to world / absolute?

It will not rotate with the character then and stay aligned with the world.
Can also be used with an invented cylinder to have a skyrim compas at the top of the screen (would just need some form of alpha fade nearing peripheral vision)

You just need a long texture strip with N → E → S → W along cylinder wall & inverted normals so they are inside.

This is what I’m trying to do. The compass at the bottom tracks certain actors as they move (see the green bar). The problem is my function that adds the green bar, called Mark. The Mark function is called at some point when the actor begins moving. For now, I have it on begin play for testing purposes, but it won’t actually be begin play. Taking it off of begin play does not fix it though. As far as how it tries to access the widget, refer to my first screenshot.

I was asking questions for a reason. It’s rather clear that things are not set up right:

image

Yet you cast:

Is there more that we should know about this disparity? Are you using / possessing the right character to start with?

I am trying to access this widget from an actor component, within my own function. It is not in any construct or tick functions

Does from an actor component mean that you’re trying to access the widget from a completely unrelated component that also belongs to the / a player class? There is nothing wrong with the snippet you’re showing. More info needed.

Just to add 2 cents to the discussion. If the call is right at the beginning of initialization then the widget may not be ready. Adding a delay for local tests (0,2 seconds) proves that if the cast is ok it is valid.

Maybe add a delegate call from the ui once it’s loaded to let the function know it’s safe to access it.


1 Like

This. I really dislike the whole component initialisation order thing. It’s like a staple I now avoid. Extend widget component → have it reach out to the owning actor → hook up dispatchers, done.

I switched to the first person character real quick to get that screenshot of the working compass. It works on that character. On BP_MainPlayerCharacter (which is a VR character) it doesn’t. The snippet I showed is the only place this component is ever referenced. Here is a picture of the HUD component on the character:

Through using prints and breakpoints, I know getting the character works. I know casting to BP_MainPlayerCharacter works. I know getting HUD works. Get User Widget Object is definitely where it breaks, because it is null, but if you look at the character class, it is obviously set to a class.

Though to keep it cleaner I would probably migrate the character logic UI to the HUD class. (then the cast would be to the hud class)

There is really no need to be constantly polling the character, especially if you decide to unpossess / possess other characters then the whole system breaks.

Maybe a decoupling with interfaces could help.

How many HUDs do you have in the variable list? Only one in the component list and nothing else below?


I am trying to figure out how to break it rather than how to make it work, tbh:

image

There was a UE version where the top one did not work.

  • is there anything special about the component itself?
  • are you using any plugins?
  • what are the chances you replace the component’s widget at some point with:

image

Widget

Character with interface

Hud BP

Interface

All decoupled and you can switch out the character as long as it implements the interface

compasProj.zip (1.1 MB)

@3dRaven and @Everynone Thank you for the help yesterday. It’s the weirdest thing, but I logged on this morning, deleted the Get User Widget Object node, and put another one in it’s place, and everything works now. That shouldn’t have fixed it, and even if it should’ve, I did that several times yesterday, but it works, so I’m not complaining. Thanks again, guys.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.