DefaultPawnClass change role

I have used “DefaultPawnClass = AMyCharacter01::StaticClass();” to create my role,
How can I change my role (Knight → Wizard) when I am playing game?

If you want to change the pawn used by your controller it is as simple as:

  1. Cache a reference to your current pawn
  2. Unposses your current pawn (Controller->UnPossess())
  3. Spawn the new pawn using a different class
  4. Posses the new pawn (Controller->Possess(NewPawn))
  5. If all went well destroy the cached pawn, if not you could always re-posses the old one.

Cheers,
Moss

Thanks very much,

but I meet one problem,
After I changed role, camera always changed(face to new role’s back),
How can I let camera only change once as first time,
Please help me, thanks.

CameraBoom = PCIP.CreateDefaultSubobject(this, “CameraBoom”);
CameraBoom->AttachTo(RootComponent);
CameraBoom->bUseControllerViewRotation = true;
CameraBoom->bDoCollisionTest = false;

FollowCamera = PCIP.CreateDefaultSubobject(this, “FollowCamera”);
FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUseControllerViewRotation = false;

CameraBoom->TargetArmLength = 520;
AddControllerPitchInput(20);

Solved, I forgot to clear controller rotation;

So you want the camera not to follow the pawn? Or the first pawn?

I want to camera keep follow last pawn, I have solved, thanks very much.

If you issues has been solved you could accept the answer so it might help others.