How do i get the name of the streaming level that actor is present in.

Hello, I would like to make a save/load level loading system and I need to get the level name that the actor is in at that moment. I’ve tried using “Get Current Level Name” function, but it returns the main persistent level name, not the sub-level that the actor is at that moment.
Thanks in advance.

3 Likes

Have you found a solution yet?

What I’ve done is to make a save function for each level that i have and put them in each level.

Here you go:

  Actor->GetLevel()->GetOuter()->GetName();

For some reason all the ULevel-s are called PersistentLevel. Sounds like a bug to me, but who knows. Their outers have the name we are looking for tho.

I spent more time on the internet trying to find an answer to this question than I did in visual studio to find the solution of my own.

10 Likes

Thank you!Perfect!

Hey ! Was just wondering : any idea how to achieve this in Blueprints ?

Afaik you can’t. Writing a static c++ function and calling that from BP is the way to go.

That’s what I’m looking for. Too bad that I’m a total c++ noob. Can someone write full function in c++? I’m struggling an hour to get this working and I have no idea what am I doing. Anyone can help?

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

/**
 * 
 */
UCLASS()
class PROJECTNAME_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
	UFUNCTION(BlueprintPure, Category = NYTaskHelper)
	static FName GetStreamingLevelNameFromActor(AActor* Actor)
	{
		if (Actor != nullptr)
		{
			return Actor->GetLevel()->GetOuter()->GetFName();
		}

		return NAME_None;
	}
};
1 Like

Thank you for that ! Works as it should.

Hi Elathan - I’m the furthest thing from a programmer - I’ve been trying your code in a character class (but I’m worse at c++ than MadRat). I have it in the .h file but don’t see any change in the BP. Been struggling for a solid week to get the level stream name for the save object. Besides jumping off a high building have you got any advice?

Has (ULevel-s are called PersistentLevel) been sorted - because I’ve tried every variation of getWorldPackadgeFname >getstreaminglevel >Set Level Streaming name with no success - maybe the solution is simple I’m just not finding it. You are the last hope . . .

Nice finding!

You can achieve that by blueprints by writing the following : self > getOuterObject > getOuterObject > getObjectName, hope this helps someone.

6 Likes

That worked! Thanks!!

I had a similar issue but I need to find all actors of a type in a streaming level once loaded. Here was my solution for a C++ function to be accessed via Blueprints.

void UBlueprintFunctionLibrary::GetAllActorsOfClassFromStreamingLevel(UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, ULevelStreaming* StreamingLevel, TArray<AActor*>& OutActors)
{
	OutActors.Reset();

	if (ActorClass && StreamingLevel)
	{
		ULevel* Level = StreamingLevel->GetLoadedLevel();
		OutActors.Reserve(Level->Actors.Num());
		for (const auto LevelActor : Level->Actors)
		{
			if (IsValid(LevelActor) && LevelActor->IsA(ActorClass))
			{
				OutActors.Add(LevelActor);
			}

		}
	}
}

Create function into Blueprint, it will be return map name.