I’ve run into a problem with forward declarations.
Suppose I forward declare a class called “MyObject” to be used inside my character, and in my character, I want to create a new object of type “MyObject”, how would I go about doing this?
Usually I’d do
MyObjectPointer = NewObject<UMyObject>(this, UMyObject::StaticClass());
This gives an error:
“Incomplete type is not allowed”
Any help would be appreciated.
You can’t instantiate an instance of a class without having the full definition. Forward declaring is fine for headers, but in the cpp you’re going to have to include the header that defines MyObject to get the boilerplate code you need.
You can use this code:
UClass *MyObjectClass= LoadClass<UObject>(NULL, TEXT("/Script/ModuleName.MyObjectClass"), NULL, LOAD_None, NULL);
MyObject* Object = ConstructObject<MyObject>(MyObjectClass);