Download

Getting current stream level?

Hello! I am working on trying to make sure my character does not fall through the ground on gameplay.
I am using World Composition and am trying to figure out if there is a way to get the current streamed level a player is in?
I am planning on using it to pre load that level when the level is loaded, then after that is complete it will set the players gravity scale back to 1 to allow them to fall to the ground.
Just to clarify, I already can already detect when a streaming level is loaded, I am just trying to get the players current streamed level.
This is currently an all Blueprint project.
Any help is appreciated! Thanks!

I have a bit of a workaround for blueprints. If you spawn an actor and then play with the path name of the actor you can extract the level. There is probably a better way to do it in C++

The answer above is not correct, it will report the name of the parent level, not the current stream level loaded.

Did anyone find a way to get the current sub level where the player is in?

I’ve seen this crop up quite a lot and never seen a good solution.

I think the best thing is just to keep a record of what level(s) you have streamed in the game instance or save game, then you know…

A complete solution can be found here:
http://www.ostinelli.net/ue4-get-actor-current-streaming-sub-level-name

It requires C++, but it exposes a BP node.

Hi, the page returns 404, can you post the solution here or fix the broken URL? Thanks.

Create MyFunctionLibrary.h:


#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameFramework/Actor.h"
#include "MyFunctionLibrary.generated.h"

UCLASS()
class YOURPROJECTNAME_API UMyFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    // Get Sub Level name
    UFUNCTION(BlueprintPure, Category = NYTaskHelper)
    static FName GetActorStreamingLevelName(AActor* Actor);
};

And MyFunctionLibrary.cpp:


#include "MyFunctionLibrary.h"

FName UMyFunctionLibrary::GetActorStreamingLevelName(AActor* Actor)
{
    if (Actor != nullptr)
    {
        return Actor->GetLevel()->GetOuter()->GetFName();
    }
    return NAME_None;
}

Save and compile. This will expose a new node in your Blueprints. Just input the actor you’re looking to find the Streaming Level name for.

Credits to Elathanfor first exposing the solution.

I tried this solution already, as its on the web, but its not correct.

This is returning the Persistent level and not the current streaming level. So for example if you have a Persistent Level called One, and a sublevel called Two, if you load inside the level Two, the code above will report “One”, which is not answering to the original question.

I don’t know what you mean with “if you load inside the level Two”, but this code works as expected for an actor that is spawned in the sublevel.

Hi, “with load in level Two” I mean the character position is inside the level Two. I tested it before posting my response, and as I said it returns “One” and not “Two”. Where One is the Persistent level (top of the structure), in my case the container of world composition, and Two is one sublevel , one map of the world composition.

I really need to solve this problem btw, so if you have a working setup, and some time to spare, please join our discord, and we can chat about it. Maybe my setup is different than yours in some ways.

You might be confusing the *location *of an actor with the level it belongs to. The above code returns the level an actor belongs to, which is what you can see in the editor:

This thread is about dynamic actors, added on the fly to a game when the player loads in, and where the game is setup to use streaming levels. Your screenshot shows an actor statically placed in a level. I think we are speaking of different scenarios.

The original thread wasn’t about dynamic actors, the first response was, so this thread ended up talking about different things. :slight_smile:

Anyway, maybe I need to make myself more clear and feed you with some ideas: the code I’ve provided you with returns the streaming level name of an actor placed in a level. Which means that you can recover the level name for instance by getting one of the actors your character is near to (for example the ground). An example in BP could go something like this:

That said, in general what you want to achieve is way simply achieved by using collision volumes that encompass your levels, so that you can either use triggers or even query the overlapping actors when needed, for example:

Hope this clarifies and helps. Cheers.

1 Like

This solution worked for me for placed actors. Getting Outer’s FName on the Level returned the streaming level name instead of “Persistent Level”. I can’t verify for dynamic actors, but this definitely works for placed actors.

What above this did not work for those who tried? My simple test of linetracing down from the player pawn until it hits an actor shows that it does return the streaming sublevel that the actor is in.

(Also, holy ■■■■, the overall support in Blueprints for level management is extremely inadequate… like so many things in Blueprints sadly.)

EDIT: And sigh… of course there’s an answer in C++ and Blueprints are screwed over as usual… How to get currently loaded level names - UE4 AnswerHub