x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 alt text alt text alt text

Product Version: UE 4.19
Tags:
more ▼

asked Aug 29 '18 at 09:07 AM in Blueprint Scripting

avatar image

leadermax
65 3 9 18

avatar image Everynone Aug 29 '18 at 09:48 AM

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?

avatar image leadermax Aug 29 '18 at 09:59 AM

I hope the screenshots I added answer you!

avatar image Tuerer Aug 29 '18 at 09:54 AM

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.

avatar image leadermax Aug 29 '18 at 10:00 AM

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!

avatar image Tuerer Aug 29 '18 at 10:06 AM

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.

avatar image leadermax Aug 29 '18 at 10:17 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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)

more ▼

answered Aug 29 '18 at 09:59 AM

avatar image

dZh0
1.3k 6 5 9

avatar image leadermax Aug 29 '18 at 10:04 AM

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?

avatar image Tuerer Aug 29 '18 at 10:09 AM

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

avatar image leadermax Aug 29 '18 at 10:14 AM

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!

avatar image Tuerer Aug 29 '18 at 10:19 AM

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

avatar image leadermax Aug 29 '18 at 10:31 AM

it works! I feel kinda dumb...I should at least have tried :/ Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question