GKoch
(WFG)
August 23, 2022, 5:53pm
1
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.
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.
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.
Rumzie
(Rumzie)
August 23, 2022, 6:38pm
2
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
GKoch
(WFG)
August 23, 2022, 6:47pm
3
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.
Rumzie
(Rumzie)
August 23, 2022, 6:53pm
4
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.
GKoch
(WFG)
August 23, 2022, 6:54pm
5
do you have an example of a blueprint snippet you could show me?
Rumzie
(Rumzie)
August 23, 2022, 6:55pm
6
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
metalxx-x
(metalxx-x)
August 24, 2022, 7:29pm
8
Hi I think the level files are .umap or I missing something ?