How do I get a reference to the Level Blueprint?

I have an Actor that has a “time until ready” property.
I have a GUI, created by the level blueprint, that has a “time until ready” progress bar.
I would prefer for the object to just tell the level how ready it is, and the level to decide how to display that (such as updating the GUI.)

I understand how I can pass a reference to the GUI to the Actor. But that’s not what I want to do.
How can I get a reference to the Level from the Actor?
Or should I use a Custom Event for this?

Hi,

Cast to the current level is not possible cause each level can be different. Nevertheless if you want to do this, you have to dive deep within C++.

But i would not recommend this.

My advice: Keep all your Level BPs empty and use Custom BPs and spawn them when needed. This way you can develop independent of Levels. You can change GameMode and thus load the components that you currently want to use.

The trick, if want to know what level is currently loaded without writing code, is:

  1. Create a custom BP (I recommend an Actor BP) and call it for example “LevelMarker”
  2. Put this BP into your Level and give it the name of the level where the BP was placed in
  3. This BP should exist only one time per level
  4. You can now access the current level by “Get all Actors from Class”, the Class is “LevelMarker”
  5. Just watch the picture: This tells you how to test or use it

Remember: You can do things for several levels by “if then else”, but not select certain parts of the level itself.

Hope that helps :smiley:

If you do not like this solution and do not want to write code then your “Custom Event” solution is probably the the best.

Cheers :smiley:

2 Likes

He should just use the GameState class for this. This class is designed to contain information about the state of the Game and it is reseted for each level.

If he wants to provide level specific information, then he can get the GameState in the LevelBlueprint and set different values.

The GameState can be accessed easily by just searching for “GameState” in a graph. You can create our own GameState Blueprint and set it in the Maps and Nodes or in the Default Settings of you GameMode Blueprint.

You can also have a look at the PlayerState class. You can create your own and set it inside the GameMode Blueprint Default settings (only there. not in the maps and nodes). The GameState contains an array of all PlayerStates if you are running a MultiplayerGame.

1 Like

OK, seems like using the level blueprint isn’t that useful, then.
By the way, what is the single page that tells me the lifetime / reset-times / intended state of each of the GameState, PlayerController, GameMode, and Level classes? (This information may be possible to gather by reading all of the documentation end-to-end… but if someone already did that, everyone would save time, including me :slight_smile:

If you want to communicate with the level blueprint from a class blueprint youll need to use an event dispatcher.
Its the same principle as “cast to level blueprint”

link

2 Likes

Hello!
In fact this can be done via the BP-Interface.
In Level BP using the message from the input parameter BPI with Object, and through which pass a reference.

1 Like

A fairly easy workaround for this limitation is to create event listeners in your GameMode Blueprint or your Player Blueprint, then bind to / call them from the Level Blueprint.

Since you can get references to these BPs from pretty much any other blueprint (using the “Get GameMode” or “Get Player Pawn/Character” nodes), you can just get a reference to the GameMode or Player (you may have to cast it) in the Level Blueprint, then bind events to the listeners in those blueprints and/or call those listeners.

1 Like

Thanks for that link man. Solved my issue.

wish everyone would stop proposing eventDispatchers like they have anything to do with blueprints communication, they just letting to execute different events in same time, basicaly helpfull in terms of parenting (eventHit and similar things which should execute something for all clild classes and can be used to execute additional scripts in theses classes is actualy eventDispatchers)

I made a quick tutorial for this (event dispatcher can help)

3 Likes

@ilias, Unreal disagrees. Event Dispatchers are clearly considered a form of blueprint communication per the documentation.

Thank you so much for this, solve my problem

hello, i also wanted to share the way i reference the level blueprint.
The main idea is making the level blueprint implement an interface then using variables of that interface in your actors.
i made a video showing it : Reference to LevelBlueprint - unreal engine - YouTube

I used this method because i got to work in someone else project, with all the code placed in the blueprint, and it was so much code i just had to find a way to get a direct reference to all the functions and custom methods living in the levelblueprint.

1 Like

That works, amazing!

Am a bit late on this one but EPIC Literraly placed event dispatcher in their “blueprint communication” section of the support page. Its also very badly explained, as I also tried to use event dispatcher as a mean of inter blueprint communication :

As you can see on the spreadsheet at the bottom of this page, they propose event dispatcher as a mean of interblueprint communication. Which is dumb because it creates tons of timming issues and the event dispatcher timeframe is very easy to miss by another blueprint. I use custom event instead but they also complicate the code since you sometimes trigger something out of an event and sometimes not.

What do you mean by timeframe?

Meaning that the event dispatcher doesn’t queue or flag which is what I though it would. It fires like a custom event. So you need to make sure the blueprint supposed to receive the dispatched event is valid and active at the moment the dispatcher will fire. In the end I don’t see any use for it as I can use custom events for it.

How exactly is Game State going to bring him the level name, or any information about the level?