I’m creating a game where the player could potentially play 100s of different pawns, each with their own collisions, meshes, animations, etc(All defined in Blueprints in the end). However they all share the same underlying inputs & functions. So as a result I’ve handled the movement inputs in the PlayerController which passes on the inputs to functions in a custom pawn class. Or in code:
[SPOILER]
Player Controller.ccp
//The *** mean A S S (My Game Name is Abbreviated to SS & Actor Classes are prefixed with A so... A S S is my prefix for actor classes XD)
void ***_MP_PlayerController_Master::SetupInputComponent()
{
Super::SetupInputComponent();
check(InputComponent);
if (InputComponent)
{
UE_LOG(LogTemp, Error, TEXT("InputComponent working!"));
//Movement Controls
InputComponent->BindAxis("MoveForward", this, &***_MP_PlayerController_Master::MoveForward);
} //This is a virtual void function btw
void ***_MP_PlayerController_Master::MoveForward(float AxisValue)
{
if (!PPawn && AxisValue == 0.f) {return;}
else
{
PPawn->MoveForward(AxisValue);
}
}
[/SPOILER]
Basically I plan to create the following
Master_Pawn
Master_Character
[INDENT=2] (These will be in Blueprints)
[/INDENT]
[INDENT=2] Lion
Sheep
Robot
Robot_Dog
Human
Alien
etc
etc
etc
[/INDENT]
Spectator_Pawn
Menu_Pawn
I Currently Cast to the Master Pawn. Now from my understanding of child actors(I'm rather new to C++ so I might be wrong, please correct me if I am) the virtual void function will be called on the child no matter if its overridden. So that way I can define input in the Master_Pawn Class and Character classes that will then be inherited on the Lion, Sheep, etc classes unless its overridden. This way I don't have to define the same inputs 100 times over.
[SPOILER]
//This is called whenever a Pawn is Possessed from my understanding
void ***_MP_PlayerController_Master::BeginPlayingState()
{
Super::BeginPlayingState();
PPawn = Cast<***_MP_Pawn_Master>(GetPawn());
if (!PPawn)
{
UE_LOG(LogTemp, Error, TEXT("Player Controller Failed to Cast to Player Pawn. Make sure Player Pawn is of type ***_MP_Pawn_Master!"));
return;
}
}
[/SPOILER]
However this currently means that the cast will fail for all of the children using the current method so I can’t call the input functions on the sheep for example . I would use static_cast(Which I believe lets me go down), but from what I’ve read Unreal doesn’t support that C++ type. So what’s the correct way of implementing the above system in Unreal? Is their a different casting function I could use that uses static casting?
EDIT: Should I be creating a custom C++ component, on the pawn, which I then cast to that sets up the default input functions instead of the Pawn itself? Would that be the correct way to implement this code?