Download

ULevelStreaming::CreateInstance() causes build failure!

I just trying to make a new instance of the level. and the code is fairly simple.

#include “WorldGeneration.h”
#include “Unfinished.h”
#include “Engine.h”
#include"Engine/LevelStreaming.h"

float tempTime = 0;
void AWorldGeneration::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
tempTime += DeltaTime;
ULevelStreaming* temp = UGameplayStatics::GetStreamingLevel(GetWorld(), TEXT(“CityGeneration”));
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::SanitizeFloat(tempTime));
if (tempTime > 10) {
temp->bShouldBeLoaded = true;
temp->bShouldBeVisible = true;
temp->CreateInstance(FString(TEXT(“PleasWork”)));
}
}

Now yes I know the var names are bad, but the point of this was to see if I could get the CreateInstance() to work. The rest of the code works perfectly in tell the line temp->CreateInstance(FString(TEXT(“PleasWork”))); is added in. When it is added the code fails to build returning.

1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: Unfinished, Configuration: Development_Editor x64 ------
2>Compiling game modules for hot reload
2>Performing 3 actions (9 in parallel)
2>WorldGeneration.cpp
2>[2/3] Link UE4Editor-Unfinished-2719.dll
2>[3/3] Link UE4Editor-Unfinished-2719.lib
2> Creating library D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-2719.lib and object D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-2719.exp
2> Creating library D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-2719.suppressed.lib and object D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-2719.suppressed.exp
2>WorldGeneration.cpp.obj : error LNK2019: unresolved external symbol “public: class ULevelStreaming * __cdecl ULevelStreaming::CreateInstance(class FString)” (?CreateInstance@ULevelStreaming@@QEAAPEAV1@VFString@@@Z) referenced in function “public: virtual void __cdecl AWorldGeneration::Tick(float)” (?Tick@AWorldGeneration@@UEAAXM@Z)
2>D:\Game Creation\Projects\Unfinished\Binaries\Win64\UE4Editor-Unfinished-2719.dll : fatal error LNK1120: 1 unresolved externals
2>UnrealBuildTool : error : UBT ERROR: Failed to produce item: D:\Game Creation\Projects\Unfinished\Binaries\Win64\UE4Editor-Unfinished-2719.dll
2>Total build time: 16.31 seconds (Local executor: 0.00 seconds)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ““D:\Game Creation\UE_4.19\Engine\Build\BatchFiles\Build.bat” UnfinishedEditor Win64 Development “D:\Game Creation\Projects\Unfinished\Unfinished.uproject” -WaitMutex -FromMsBuild” exited with code 5. Please verify that you have sufficient rights to run this command.
2>Done building project “Unfinished.vcxproj” – FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is in a public AActor, if there is something else that I should use please let me know any help would be appreciated.

So, I thought that I would get smart and call it from a blank c++ file. I’m sorry to say that this did not fix the problem

This is very simple code, or so i thought

=======cpp File==========

#include “LevelSpawnTest.h”
#include “Engine/LevelStreaming.h”

LevelSpawnTest::LevelSpawnTest()
{
}

LevelSpawnTest::~LevelSpawnTest()
{
}

void LevelSpawnTest::CreateNewWorld(FString pName, ULevelStreaming* pLevelType, FTransform pTransform) {
pLevelType->CreateInstance(pName);
}

========h file===========

#pragma once

#include “CoreMinimal.h”

class UNFINISHED_API LevelSpawnTest
{
public:
LevelSpawnTest();
~LevelSpawnTest();
void CreateNewWorld(FString pName, ULevelStreaming* pLevelType, FTransform pTransform);
}

=========error message===============

1>------ Build started: Project: Unfinished, Configuration: Development_Editor x64 ------
1>Compiling game modules for hot reload
1>Performing 3 actions (9 in parallel)
1>LevelSpawnTest.cpp
1>[2/3] Link UE4Editor-Unfinished-7811.dll
1>[3/3] Link UE4Editor-Unfinished-7811.lib
1> Creating library D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-7811.lib and object D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-7811.exp
1> Creating library D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-7811.suppressed.lib and object D:\Game Creation\Projects\Unfinished\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-Unfinished-7811.suppressed.exp
1>LevelSpawnTest.cpp.obj : error LNK2019: unresolved external symbol “public: class ULevelStreaming * __cdecl ULevelStreaming::CreateInstance(class FString)” (?CreateInstance@ULevelStreaming@@QEAAPEAV1@VFString@@@Z) referenced in function “public: void __cdecl LevelSpawnTest::CreateNewWorld(class FString,class ULevelStreaming *,struct FTransform)” (?CreateNewWorld@LevelSpawnTest@@QEAAXVFString@@PEAVULevelStreaming@@UFTransform@@@Z)
1>D:\Game Creation\Projects\Unfinished\Binaries\Win64\UE4Editor-Unfinished-7811.dll : fatal error LNK1120: 1 unresolved externals
1>UnrealBuildTool : error : UBT ERROR: Failed to produce item: D:\Game Creation\Projects\Unfinished\Binaries\Win64\UE4Editor-Unfinished-7811.dll
1>Total build time: 2.92 seconds (Local executor: 0.00 seconds)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ““D:\Game Creation\UE_4.19\Engine\Build\BatchFiles\Build.bat” UnfinishedEditor Win64 Development “D:\Game Creation\Projects\Unfinished\Unfinished.uproject” -WaitMutex -FromMsBuild” exited with code 5. Please verify that you have sufficient rights to run this command.
1>Done building project “Unfinished.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I will conteniue to post if there are any more developments, oh and there is nothing calling this I was just trying to build.

It’s an unresolved external, which usually means the function you’re calling can’t be found. Placing it in another file won’t make a difference.

I’m willing to bet that ULevelStreaming::CreateInstance is actually marked with Editor_Only and not available in a packaged game. It’s either that, or you don’t have the required module in your build.cs file

Just as an update i’m currently trying to find around this issue with out simply using blueprints, because the system I want to implement is complex and a blueprint would not be fun. But, I have found that it seems to be something with just these lines of code.

ULevelStreaming* CreateNewLevel(ULevelStreaming* LevelTarget, UWorld* WorldTarget, FString name) {
ULevelStreaming* NewLevel = nullptr;
return NewLevel;
}

I have given up on trying to use the one give to us by the devs and have decide to try and make my own however, these three simple lines right here cause the same build failure.

A simple Google search will show you why this failure happens.
Those classes either have functions wrapped within a #WITH_EDITOR directive and/or is marked MinimalAPI.

Yup! Told ya so… There’s probably a good reason they are marked for editor only, you’ll have to come up with something else or at the very least modify the engine source code.

So I found a way around it “Not the Greatest”. The way that I did it was I used a UPROPERTY to pass the Level Names through to the Blue Print. It was sort of a pain but it does work