How to switch pointer value between parent and child?

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!

Hello! If you want to use CurrentStance for switching, you dont need this line

CurrentStance = CreateDefaultSubobject<UBaseStanceComponent>(TEXT("Current Stance"));

just set it to nullptr or default stance…

Thanks for the reply! However, I don’t think this is a solution, because say I do initalise CurrentStance to nullptr, when it comes to setting the pointer to Air I still have the same problem.

It seems like you should be able to. Is there a particular reason you don’t just

  Cast<UBaseStanceComponent>(Airstance)

?