String reference doesn't work?

I know for the purposes of my project i should probably use seamless travel, however, i am trying this while prototyping.

here’s the code to travel to a server. I am using this as an exec command.

image

However, when i type the command on my lobby level nothing happens. I get an on-screen message saying “Hosting” as per my UE log.

I guess it’s not finding the map i want to travel to.

image

When I right click the asset and select “Get reference path” i get:

World’/Game/Maps/ArenaMap.ArenaMap’

I’ve also tried using:

“/Game/Maps/ArenaMap/”

Nothing seems to work.

Here is how UGameplayStatics handles it, hope something in here is useful to you.

void UGameplayStatics::OpenLevel(const UObject* WorldContextObject, FName LevelName, bool bAbsolute, FString Options)
{
	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
	if (World == nullptr)
	{
		return;
	}

	const ETravelType TravelType = (bAbsolute ? TRAVEL_Absolute : TRAVEL_Relative);
	FWorldContext &WorldContext = GEngine->GetWorldContextFromWorldChecked(World);
	FString Cmd = LevelName.ToString();
	if (Options.Len() > 0)
	{
		Cmd += FString(TEXT("?")) + Options;
	}
	FURL TestURL(&WorldContext.LastURL, *Cmd, TravelType);
	if (TestURL.IsLocalInternal())
	{
		// make sure the file exists if we are opening a local file
		if (!GEngine->MakeSureMapNameIsValid(TestURL.Map))
		{
			UE_LOG(LogLevel, Warning, TEXT("WARNING: The map '%s' does not exist."), *TestURL.Map);
		}
	}

	GEngine->SetClientTravel( World, *Cmd, TravelType );
}

void UGameplayStatics::OpenLevelBySoftObjectPtr(const UObject* WorldContextObject, const TSoftObjectPtr<UWorld> Level, bool bAbsolute, FString Options)
{
	const FName LevelName = FName(*FPackageName::ObjectPathToPackageName(Level.ToString()));
	UGameplayStatics::OpenLevel(WorldContextObject, LevelName, bAbsolute, Options);
}

You probably start with OpenLevelBySoftObjPtr since you can find the level by name in that way

Hi! thanks for your reply.

I tried searching in the documentation for OpenLevelBySoftObjPtr, but nothing comes out.

However, studying the snippet you show here I think that the way I tried to use ServerTravel should work, shouldn’t it?

by just passing the URL as a string.

I would assume your code should work, but I’ve never done it from c++. I do know the blueprint method to work. The Snippet is the c++ code called from blueprints.

The function I’m speaking of is at the very bottom of the snippet.

do you have an example of a blueprint snippet you could show me?

image

This function is calling the snippet

Have you tried: World->ServerTravel( "ArenaMap" ); ?

All the server travels in my project are either of the form (translated to your asset): “ArenaMap” or “/Game/Maps/ArenaMap”.

It seems like you may have tried to do the second one but your text has an extra “/” at the end. I don’t know if that’s a mistake when posting here or with what you actually tried.

1 Like

Hi I think the level files are .umap or I missing something ?