# Unresolved External with CreateInstance (from UGameplayStatics)

**URL:** <https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932>\
**Category:** World Creation\
**Tags:** compiling, Level-Streaming, unresolved-external-, unreal-engine, question\
**Created:** [November 14, 2014, 2:43pm UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932 "2014-11-14T14:43:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Arts\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mark\_Arts\_1](https://forums.unrealengine.com/u/Mark_Arts_1)\
**Post date:** [November 14, 2014, 2:43pm UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/1 "2014-11-14T14:43:29Z")

</div>

When compiling the following code

```
	ULevelStreaming* NewLevel = UGameplayStatics::GetStreamingLevel(GetWorld(), TargetLevel);
	NewLevel = NewLevel->CreateInstance(UniqueName);
	NewLevel->bShouldBeLoaded = true;
	NewLevel->bShouldBeVisible = true;
	NewLevel->LevelTransform = FTransform(
		FQuat(0.f, 0.f, 0.f, 0.f),
		FVector(0.f, 0.f, 0.f),
		FVector(0.f, 0.f, 0.f)
	);

```

I get the following errors:

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?

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [November 14, 2014, 3:09pm UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/2 "2014-11-14T15:09:01Z")

</div>

Hi, if you need ULevelStreaming add ENGINE\_API

```
class ENGINE_API ULevelStreaming : public UObject

```

and remove ENGINE\_API from other methods;

Regards

Pierdek

---

<div class="post-metadata">

**Author:** ![Mark\_Arts\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mark\_Arts\_1](https://forums.unrealengine.com/u/Mark_Arts_1)\
**Post date:** [November 14, 2014, 4:15pm UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/3 "2014-11-14T16:15:29Z")

</div>

Hey Pierdek,

I’m pretty new to Unreal and c++ programming but do i need to edit the Levelstreaming.h file?

When i add ENGINE\_API and remove the ENGINE\_API before the functions of ULevelstreaming I get following error

error : In LevelStreaming: MinimalAPI cannot be specified when the class is fully exported using a MODULENAME\_API macro

Then when i remove MinimalAPI from the UCLASS macro

```
UCLASS(abstract, editinlinenew)
class ENGINE_API ULevelStreaming : public UObject

```

I get the following error:  
error C2487: ‘GetPrivateStaticClass’ : member of dll interface class may not be declared with dll interface

I tried adding ENGINE\_API before create instance because i can call the GetWorldAssetPackageFName() but that still resolved in unresolved externals.

```
ENGINE_API ULevelStreaming* CreateInstance(FString UniqueInstanceName);

```

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [November 15, 2014, 12:40pm UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/4 "2014-11-15T12:40:45Z")

</div>

Ok, if that doesn’t help you can always add your functionality to the UGameplayStatics;

---

<div class="post-metadata">

**Author:** ![Mark\_Arts\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mark\_Arts\_1](https://forums.unrealengine.com/u/Mark_Arts_1)\
**Post date:** [November 26, 2014, 7:57am UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/5 "2014-11-26T07:57:18Z")

</div>

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;
}

```

---

<div class="post-metadata">

**Author:** ![klobodnf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@klobodnf](https://forums.unrealengine.com/u/klobodnf)\
**Post date:** [December 21, 2023, 11:21am UTC](https://forums.unrealengine.com/t/unresolved-external-with-createinstance-from-ugameplaystatics/298932/6 "2023-12-21T11:21:09Z")

</div>

```auto
UCLASS(abstract, editinlinenew)
class ULevelStreaming : public UObject

```

You can remove ENGINE\_API fixed MinimalAPI issuse
