Hello! I have a function that switches between stances (Earth, Wind, Fire etc). To implement this I have a switch function that swaps the pointer value of ‘CurrentStance’ to the new stance. Here I state the parent/child relationship between the classes:
class UBaseStanceComponent : public UActorComponent;
class UAirStanceComponent : public UBaseStanceComponent;
// ...
class AMainCharacter : // ...
{
UBaseStanceComponent* CurrentStance;
UAirStanceComponent* AirStance;
// ...
};
Now I assign the pointers to their respective objects:
CurrentStance = CreateDefaultSubobject<UBaseStanceComponent>(TEXT("Current Stance"));
AirStance = CreateDefaultSubobject<UAirStanceComponent>(TEXT("Air Stance"));
Finally we have the switching function that changes the pointer of CurrentStance to the new stance:
void AMainCharacter::ChangeStance(EStance Stance)
{
switch(Stance)
{
case EStance::AirStance:
CurrentStance = AirStance;
break;
The penultimate line causes the following error:
Cannot assign to type 'UBaseStanceComponent*' from 'UAirStanceComponent*'
However surely this should be fine given Air inherits from UBaseStanceComponent? Any help would be greatly appreciated. Thank you!