I’m building a character in C++, and I want to have a weapon component which is instantiated from a class which can be set in blueprint. In my .h file I have this to parametrize the class:
/** Weapon class to spawn */
UPROPERTY(EditDefaultsOnly, Category="Weapon")
TSubclassOf<class UWeaponBaseComponent> InitialWeaponClass;
Then in the .cpp I am trying to instantiate like my other components, but it’s throwing an error:
MyCharacter::MyCharacter(const FObjectInitializer& ObjectInitializer):Super(const FObjectInitializer& ObjectInitializer)
{
//...
currentWeapon = CreateDefaultSubobject<InitialWeaponClass>(TEXT("InitialWeaponComponent"));
//...
}
The error I get is No matching function to CreateDefaultSubobject
.
So I guess InitialWeaponClass is not a class
which can be passed to the template function CreateDefaultSubobject
. What’s the right way to do this?