Download

Creating a new object but missing argument

I have a QuestManager header which contains this TAarray that contains my Quest object.


 TArray<AQuest*> currentQuest;

and my my QuestManager constructor, I am trying to add a new object to this TArray


 currentQuest.Add(NewObject<AQuest>(*findRow->questName, *findRow->questDescription));

But here is where I keep getting this error:

Error 1 error C2665: 'NewObject' : none of the 2 overloads could convert all the argument types

and this is my output

C:\Users\daniel\Documents\Dark Rising Studios\DRSDEPOT\Immortal Dawn[Unreal Project]\ImmortalDawn 4.9\Source\ImmortalDawn\QuestManager.cpp(26): error C2665: 'NewObject' : none of the 2 overloads could convert all the argument types c:\program files\epic games\4.9\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(1134): could be 'T NewObject(UObject ,FName,EObjectFlags,UObject ,bool,FObjectInstancingGraph )' with  T=AQuest ] c:\program files\epic games\4.9\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(1122): or 'T NewObject(UObject ,UClass ,FName,EObjectFlags,UObject ,bool,FObjectInstancingGraph *)' with  T=AQuest ] while trying to match the argument list '(const FString, const FString)'

this my my Quest constructor:


 AQuest::AQuest(const FString qName, const FString qDescription)
 {
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     isQuestCompleted = false;
     isQuestDropped = false;
 
     name = qName;
     description = qDescription;
 }

As you can see it is really simple, i did create a temp variable as const FString to see if it’d worked, but it also didn’t, so I don’t know what the problem is.

The NewObject method does not take those arguments:

[FONT=Courier New]template< class T >
T* NewObject
(
UObject* Outer=(UObject*)GetTransientPackage(),
UClass* Class=T::StaticClass()
)

I assume you will need to provide setters/getters for those name properties and set them after creating the object.

From the name of the class AQuest I assume you’re deriving from AActor. For this task you have to use the SpawnActor function instead: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/index.html

Also your constructor should probably be the default constructor, i.e. without any (custom) arguments or at least with an FObjectInitializer argument as shown here: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Classes/index.html#classconstructor
There is also a “CustomConstructor” UClass specifier https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Classes/Specifiers/CustomConstructor/index.html but I didn’t have to use it yet.
You can also provide your own static helper functions to construct your Objects/Actors if you want.