Invalid UserWidgetObject on BeginPlay

I have two blueprints BP_Elevator and BP_Player. BP_Player has a WidgetComponent attached.

On the elevator’s BeginPlay I get a reference to the player and therefore can get access to the player’s WidgetComponent. However, when trying to access the component’s widget itself using GetUserWidgetObject, I do not receive a valid reference.

When I use a delay of 2 seconds before accessing it, I do receive a valid reference.

Is this behaviour correct? I thought components were initialized before BeginPlay is executed. Since this is a problem that occurred after updating the project to 4.23, I am not sure if this behaviour is normal or if the project somehow got corrupted or something.

This is a problem generally, things may not be ready and you need to code with that assumption in mind.

Having said that, if not much is going on, a delay of .2 should be ample…

Bit more info. Are you spawning the player? If so, waiting might make sense. If you’ve placed the player in the world, you shouldn’t need to wait…

I’m not spawning the player. I dragged it into my level and set auto possess.

There could be a delay if one BP gets initialized before another. How much is in the level and how low can you go with the delay?

I just checked the source code of UWidgetComponent. InitWidget() is called in BeginPlay(). I did not expect that, but this explains what is happening. Weird.
I figured component intialization included initializing the widget as well. Does not seem so. Bummer.

I can go pretty low. Using a delay with 0.000001 still works.

There are around 450 actors in the level, most of them static mesh actors. A couple of custom blueprints, some lights etc.