I have spent a few hours looking at trying to find the solution for this but was unable to get anything remotely relevant.
Im spawning pawns on the server to then be possessed by a player controller,
The client-side usage is mostly the PawnProxy and the Controller, where the server is the AIController and the actual Character.
To cut some of the unnecessary information out:
- Character just has the default set up information minus the camera, this will be expanded in the future to allow selection of different classes and allow me to easily set up widget interactions between them in blueprints.
- The Controller is a simple controller, handles Click to Move stuff: gets a hit from mouse input, sends that to the AIController which then uses MoveToLocation or MoveToActor depending on what was hit
- GameMode does nothing at the moment until I set up PostLogin but the idea there would practically be the fruit of what I am trying to achieve first.
At the moment all of the spawning/initialization is purely done in the PawnProxy.cpp
Construction:
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
SetRootComponent(PlayerCamera);
static ConstructorHelpers::FObjectFinder<UBlueprint> FindCharacter(TEXT("Blueprint'/Game/Blueprints/BP_XiahCharacter.BP_XiahCharacter'"));
if (FindCharacter.Succeeded())
{
CharacterBlueprint = (UClass*)FindCharacter.Object->GeneratedClass;
}
Using the Blueprint of the Character Class for future setup stuff (Loading specific information before passing it off to spawn)
BeginPlay:
Super
if(Role == ROLE_Authority)
{
SpawnCharacter();
}
SpawnCharacter:
FActorSpawnParameters SpawnInfo;
FAttachmentTransformRules AttachRules(EAttachmentRule::SnapToTarget, EAttachmentRule::KeepRelative, EAttachmentRule::KeepRelative, false);
//Spawn the Character (would contain model information/stats/skills whatever pulled from database)
XiahCharacter = GetWorld()->SpawnActor<AXiahCharacter>(CharacterBlueprint, GetActorLocation(), GetActorRotation(), SpawnInfo);
if (XiahCharacter)
{
//Attach the Controlled Pawn (PawnProxy)'s camera to the newly spawned Character
PlayerCamera->AttachToComponent(XiahCharacter->GetCameraBoom(), AttachRules);
//Set up the Default camera boom stuff, mostly taken away from the Character construction
XiahCharacter->GetCameraBoom()->bAbsoluteRotation = true;
XiahCharacter->GetCameraBoom()->TargetArmLength = 750.f;
XiahCharacter->GetCameraBoom()->RelativeRotation = FRotator(-30.f, 0.f, 0.f);
XiahCharacter->GetCameraBoom()->bDoCollisionTest = false;
//Create the AI Controller, will be the main go to for the simple replication of Click to Move
XiahAIController = GetWorld()->SpawnActor<AXiahAIController>(XiahCharacter->GetActorLocation(), XiahCharacter->GetActorRotation(), SpawnInfo);
if (XiahAIController)
{
//Possess the character, because the PlayerController will be telling the AIController where to move, but the AIController is the main controller of the character
XiahAIController->Possess(XiahCharacter);
}
}
The rest is for replicating the XiahCharacter, the XiahAIController and the PlayerCamera (No reason for that just while im going through this testing) and setting up the input components. Like the PawnProxy is literally a Shell to hold all this information, it has its own camera which is used to attach to the new character (so that it follows it properly)
As you can see, the server’s attached camera is correct in following the spring arm while pointing at the pawn, but the client only has the spring arm correct, the camera that was created for the client is attached (i assume correctly) but does not point towards the pawn.
What exactly am I missing?
I have done the same thing in blueprints (same set up of logic) and it seems to work
Link to blueprint working video
Thanks