EDIT: Since discovered it’s not the camera manager, it’s a matter of references to the Pawn. See last post.
Wondering if someone can help me with this. I’m having an issue at the moment where playing a Multiplayer game in the editor causes the game to spawn two Camera Actors at the world origin, and my clients are all using those cameras instead of the correct ones. What’s strange, is that when I unpossess and select my Player Controllers, I can see that the player controllers are looking through the correct camera in the small preview windows.
I have a custom Player Controller that has a Spring arm and a Camera component as part of it, and on BeginPlay or posession etc, I’m telling the camera to attach itself to the Pawn it possesses. This part works, and I can tell that from the preview windows, it also works fine in Single Player. The reason I’m doing this, is because I want each player controlled to manage it’s camera based on the pawn it’s possessing, and I don’t want to create camera and spring-arm components for every pawn I could possess. This enables me to do things like change to third and first person views seamlessly along with other things.
My custom Camera Manager class changes the ‘UpdateViewTarget’ function to first search for a camera on my PlayerController before doing anything else, which I know work in Singleplayer. Here’s the altered function. Non-C++ people, don’t be scared away by the code!
void ABZGame_CameraManager::UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime)
{
if ((PendingViewTarget.Target != NULL) && BlendParams.bLockOutgoing && OutVT.Equal(ViewTarget))
{
return;
}
FMinimalViewInfo OrigPOV = OutVT.POV;
OutVT.POV.FOV = DefaultFOV;
OutVT.POV.OrthoWidth = DefaultOrthoWidth;
OutVT.POV.bConstrainAspectRatio = false;
OutVT.POV.ProjectionMode = this->bIsOrthographic ? ECameraProjectionMode::Orthographic : ECameraProjectionMode::Perspective;
OutVT.POV.PostProcessBlendWeight = 1.0f;
bool bDoNotApplyModifiers = false;
ABZGame_PlayerController* BZGame_Controller = Cast<ABZGame_PlayerController>(GetOwningPlayerController());
if (BZGame_Controller != NULL)
{
UCameraComponent* ViewCam = BZGame_Controller->GetViewCamera();
//BZGame_Controller->GetViewCamera()->AttachTo(BZGame_Controller->GetCamSpringArm(), USpringArmComponent::SocketName);
OutVT.POV.Location = ViewCam->GetComponentLocation();
OutVT.POV.Rotation = ViewCam->GetComponentRotation();
OutVT.POV.FOV = ViewCam->FieldOfView;
OutVT.POV.AspectRatio = ViewCam->AspectRatio;
OutVT.POV.bConstrainAspectRatio = ViewCam->bConstrainAspectRatio;
OutVT.POV.ProjectionMode = ViewCam->ProjectionMode;
OutVT.POV.OrthoWidth = ViewCam->OrthoWidth;
OutVT.POV.PostProcessBlendWeight = ViewCam->PostProcessBlendWeight;
if (BZGame_Controller->GetViewCamera()->PostProcessBlendWeight > 0.0f)
{
OutVT.POV.PostProcessSettings = ViewCam->PostProcessSettings;
}
if (!bDoNotApplyModifiers || this->bAlwaysApplyModifiers)
{
ApplyCameraModifiers(DeltaTime, OutVT.POV);
}
SetActorLocationAndRotation(OutVT.POV.Location, OutVT.POV.Rotation, false);
UpdateCameraLensEffects(OutVT);
}
else
{
Super::UpdateViewTarget(OutVT, DeltaTime);
}
}
In multiplayer, my cameras for all of the clients immediately switch to the one that the game spawns at the world origin by default. ShooterGame also spawns these cameras, but it uses the Pawn as a view Target I believe.
So… any ideas? I’ve trawled through answerhub and the forums to no avail so far. I suspect the issue is stemming either from the Player Controller or from the Camera Mananger. I also tried to use the ‘SetViewTarget’ function and pass in the PlayerController, but doing that causes the Manager to use my Pawn’s location and rotation instead. Very bizarre.