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"

How to get level name in BP?

I know that you can do it using C++, but how to do it with blueprints?

I'm setting up a save game blueprint and need this to make it work. The idea is to save the level name as a variable, and then load the saved level name when the game is loaded.

Product Version: Not Selected
Tags:
more ▼

asked Oct 24 '14 at 04:47 AM in Blueprint Scripting

avatar image

starfighterdude
144 15 23 145

avatar image shiwron Sep 01 '16 at 07:54 AM

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.

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

5 answers: sort voted first

I know this is an old thread, but they recently added a 'Get Current Level Name' function to BP. I thought I'd leave this answer here for you and anyone stumbling upon this thread.

more ▼

answered Oct 19 '15 at 12:07 PM

avatar image

jens1101
48 2 15 12

avatar image MJBrune Jul 10 '17 at 10:04 AM

Very cool. I just found this as a much better way to get the level name as this parses it for you. It's also in UGameplayStatics so it's very accessible in C++ as well.

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

You will have to do this with C++ and create a custom node for now (as of UE4.6.1 there's still no node).

To get the current level name:

 GetWorld()->GetMapName()

But the level name is prefixed, depending where it runs (PIE, Window), so, in order to get the prefix:

 GetWorld()->StreamingLevelsPrefix

Then you can perform a string replace removing the prefix and get the level name :)

more ▼

answered Dec 17 '14 at 10:55 PM

avatar image

karlozm
11 1 1

avatar image DrHobo Dec 01 '17 at 04:12 AM

Love it. Here's the shorthand:

 FString mapName = GetWorld()->GetMapName().Mid(GetWorld()->StreamingLevelsPrefix.Len());


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

Afaik there is no variable for that.

It could be complicated, especially for level streaming. Since one host level can load several others.

Haven't tried, but each lvl can execute on load event and append name in array of loaded levels.

Since the only way to load level is provide it's name - I don't see any reason to make that variable hardcoded. Level - top element of hierarchy. It's level who loads everything else. (I guess the chance of being inside of level that was mystically loaded is fairly low).

more ▼

answered Oct 24 '14 at 05:59 AM

avatar image

S-ed
1.4k 27 24 48

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

The .h file has...

     /** Get the currently loaded map reference name.   You have to have a sourceActor because multiple maps can be loaded/loading.
     * Typical return string is like "UIEPED_0_MyMapName" in the editor or "MyMapName" if in a stand-alone game.
     */
     UFUNCTION(BlueprintCallable, Category = TDLHelpers)
         static FString GetCurrentMapReference(AActor * sourceActor);
 

And the .cpp is...

 FString UtdlBlueprintHelpers::GetCurrentMapReference(AActor * sourceActor)
 {
     if (sourceActor == NULL)
     {
         return FString(TEXT("Must have a sourceActor (was NULL)"));
     }
 
     return sourceActor->GetWorld()->GetMapName();
 }
 
more ▼

answered Feb 21 '15 at 06:35 PM

avatar image

SND R Keene
968 31 120 113

avatar image CBFlood Mar 26 '15 at 06:22 PM

Hey, what do I put as the source actor?

avatar image SND R Keene Mar 26 '15 at 06:27 PM

The source actor is either the player actor, and then you get the top level.

If you are using tiled maps and the source actor is some tin can you dropped in the level, then the map will be the tile.

avatar image karlozm Mar 26 '15 at 06:32 PM

CBFlood,

"SND R Keene"'s solution is fine but requires you to specify an actor, to remove this requirement:

 // in the "meta" declaration add:
 "WorldContext = "WorldContextObject"
 // then in the method declaration pass the object
 class UObject* WorldContextObject

This way you can get the level name without requiring an actor, like:

  GEngine->GetWorldFromContextObject(WorldContextObject)->GetMapName();

That's it!

avatar image SND R Keene Mar 26 '15 at 07:58 PM

That is correct if you are in a single level with no tiles.

Tiles levels have multiple 'maps'

avatar image CBFlood Apr 23 '15 at 05:34 PM

Hey, I've used SND R Keene's first solution, have an actor (my game mode, where I'm using the get level code). It works great on the debug but for some reason it doesn't seem to work on an executable. Any ideas as to why that might be/potential fixes for it?

Edit: Never mind. Found out what the problem was. When using the level finder in debug it stick udpie_1_before it (or something to that effect). I used a substring to remove this part which stopped it working on the executable. All I had to do was remove the substring code and now it works on he executable (but not on the debug).

avatar image SND R Keene Apr 23 '15 at 07:26 PM

Thanks for figuring that out.

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

One simple way to do this in BP without using C++ is make your own variable in GameMode and feed ;

Create your own GameMode; Create a variable MapName into GameMode;

In your level blueprint / BeginEvent set MapName (make this all maps want to control)

Now to get map name only to do is call function:

get game mode -> cast to your game mode->get MapName

more ▼

answered Apr 15 '15 at 01:41 AM

avatar image

I-BGS-I
53 9 7 13

avatar image SND R Keene Apr 23 '15 at 07:26 PM

Yes, but this solution is for tiled world maps. So there is an overall map, and then each sub-tile is a map.

We want to be able to load/unload and create new objects into a sub-tile.

avatar image I-BGS-I Apr 23 '15 at 07:58 PM

U load the new tiles level manualy? I never work with tiles map, but if u load, u can try set again mapname in gamemode. For you know the exact name of each set of tiles you can create a structured object with Sub-tiles and your name so you get the whole load desired sub-tiles and the name of the same.

avatar image SND R Keene Apr 23 '15 at 08:29 PM

They get loaded automatically by Unreal as the player travels.

(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