Question about loading order of player controller

Hi,

I have a camera widget that’s created in my Player Controller (on beginplay). The widget allows me to select a specific camera view on screen. In my pawn blueprint (each camera is a pawn in my level) I do a “get all widgets of class”, followed by a binding to “SelectedCamera” to know which camera button was pressed on the screen. When testing it in the editor, this worked fine. Whenever I package the project, the camera widget from the Player Controller wasn’t created before the “get all widgets of class” was triggered in my pawn. I had to add a delay of 1 second inside the pawn before getting the widget. Then my problem is solved. However, it feels like there should be a better solution to this. There’s nothing going in the player controller before the widget is created so it’s unclear to me why the player controller can’t create the widget on time, before the objects (pawns) are loaded.

Am I missing something here? Any suggestions?

Delays are not a good solution, you’re right. Problem is, it’s unpredictable on different hardware, you could end up with something that just doesn’t work.

Two best ways I’ve found are:

  1. Make your own WhileDelay macro. On begin play, the macro just loops every .25 seconds or so waiting until it can see the required actor ( camera / player start etc ). Once the actor is seen then the code can continue.

  2. Create a event dispatcher somewhere that does know about when the actor is ready. Bind to that dispatcher in the blueprint that needs to wait, and connect it to a sort of delayed begin play. When things are ready, call the dispatcher and everything starts.