Access level actors from Player's HUD

I want my player to have an HUD (UMG Widget) with some buttons that control the visibility of some objects or print the position of others.

My approach is to:

  1. Have a variable in the PlayerPawn set to the reference of the HUD once it is created.
  2. In the HUD I have variables to hold the references of every actor in the level I will need.
  3. In the Level blueprint, at begin play time, I get the player pawn, cast to my specific blueprint, get the HUD reference, and set the variables with references to the level objects.

There is only one problem: since for various reasons it takes a while to spawn the player pawn, the begin play of the level is executed first, meaning that when it tries to get the player pawn and cast it and assign references, it fails the cast , because the player pawn has yet to execute it’s begin play.
If I put a delay of like 5-10 secs, everything works perfectly because in the meanwhile the pawn gets created.

Is there any better approach? I just need to access level actors from the Player Pawn.

edit: some screenshot

Alas, you cannot access level BP from other BPs, because casting requires a reference to an actor that you can’t have for a level.

Maybe you can create another empty blueprint with nothing but one event dispatcher. Bind to this event in your level BP, and call the event in your character BP when it’s done loading. And only then execute what you need in the level BP. It’s just a workaround that came into my mind, maybe it’s not the best solution.

Try to move Level blueprint (step 3) logic to the Player Pawn.

This means that you have to “set the variables with references to the level objects” in the pawn which might further delay the pawn spawning but it should work. (the main performance hit is on the “getting” of the actors)

I just need to access level actors from the Player Pawn.

Now if the actor list and the UI is not dependent on the spawned Pawn you might use another object’s begin play to do this. The widget creation needs a valid player controller regardless of weather it has a pawn or not so you can move the variables in there. (I think it is begin play is done after the level so you should have access to the actors - If not you can always use onPosses)

You’re right, if you google “how to cast to level blueprint” you will see this question was asked tons of times. You can access actors in the level by other means than casting, but you cannot access functions in the level BP from other BPs.

Try Get actors of class or Get actors with tag (add tags first), that should do the trick.

and set the variables with references
to the level objects.

How are you gathering the references? GetAll by Class, by tags, manually packing them into arrays?

I hope the screenshots I added answer you!

yeah, it’s a very smart workaround, but it seems very strange to me that there is no “official” way to do such a thing. it should be very common!

the reason why step 3 is done in level actor is because I need to access the objects in the level. I tried selecting the landscape and then right clicking in the Player Pawn blueprint, but no reference was available. please look at the screenshot I added for better explanation.
How do I access level actors like the landscape or some cubes from the Player Pawn?

ah really? I firstly wrote get actor of class but when dragging the out pin it said get a copy, and I discarded it because i thought it wouldn’t work. I’ll try!

yeah! I encountered that keyword . But the “other means” to access actors in the level are all by dispatching. And to do the binding I would need the target, meaning the player pawn cast to its blueprint. which is exactly what I don’t have unless I wait some seconds

It’s just the way arrays work, it’s totally normal.

it works! I feel kinda dumb…I should at least have tried :confused: Thanks!