error LNK1120: 1 unresolved externals
error LNK2019: unresolved external symbol “public: class ULevelStreaming * __cdecl ULevelStreaming::CreateInstance(class FString)” (?CreateInstance@ULevelStreaming@@QEAAPEAV1@VFString@@@Z) referenced in function “public: void __cdecl ADungeonLevelBlueprint::LoadLevel(class FName,class FString)” (?LoadLevel@ADungeonLevelBlueprint@@QEAAXVFName@@VFString@@@Z)
When i comment out NewLevel = NewLevel->CreateInstance(UniqueName); everything compiles fine.
I tried including #include “Engine/LevelStreaming.h” but that didn’t change anything.
Is this something that is going wrong on my end or is this be an issue with unreal?
So i managed to create a workaround for my specific problem but I have no idea if this will work as expected (We decided to take a different approach is our game).
I copied the code from ULevelStreaming::CreateInstance and adapted it to my own class that needed it (in my case it inherits from ALevelScriptActor).
Below is the implementation.
ULevelStreaming* ADungeonLevelBlueprint::CreateLevelInstance(ULevelStreaming* level, FString& InstanceUniqueName)
{
ULevelStreaming* StreamingLevelInstance = nullptr;
UWorld* InWorld = level->GetWorld();
if (InWorld)
{
// Create instance long package name
FString InstanceShortPackageName = InWorld->StreamingLevelsPrefix + FPackageName::GetShortName(InstanceUniqueName);
FString InstancePackagePath = FPackageName::GetLongPackagePath(level->GetWorldAssetPackageName()) + TEXT("/");
FName InstanceUniquePackageName = FName(*(InstancePackagePath + InstanceShortPackageName));
// check if instance name is unique among existing streaming level objects
const bool bUniqueName = (InWorld->StreamingLevels.FindMatch(ULevelStreaming::FPackageNameMatcher(InstanceUniquePackageName)) == INDEX_NONE);
if (bUniqueName)
{
StreamingLevelInstance = Cast<ULevelStreaming>(StaticConstructObject(level->GetClass(), InWorld, NAME_None, RF_Transient, NULL));
// new level streaming instance will load the same map package as this object
StreamingLevelInstance->PackageNameToLoad = (level->PackageNameToLoad == NAME_None ? level->GetWorldAssetPackageFName() : level->PackageNameToLoad);
// under a provided unique name
StreamingLevelInstance->SetWorldAssetByPackageName(InstanceUniquePackageName);
StreamingLevelInstance->bShouldBeLoaded = false;
StreamingLevelInstance->bShouldBeVisible = false;
StreamingLevelInstance->LevelTransform = level->LevelTransform;
// add a new instance to streaming level list
InWorld->StreamingLevels.Add(StreamingLevelInstance);
}
else
{
UE_LOG(LogStreaming, Warning, TEXT("Provided streaming level instance name is not unique: %s"), *InstanceUniquePackageName.ToString());
}
}
return StreamingLevelInstance;
}