Ok I have some fairly simple code to test out NetMulticast:
CPlayerController.h
#pragma once
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
#include "InputCoreTypes.h"
#include "GameFramework/PlayerController.h"
#include "CPlayerController.generated.h"
UCLASS()
class ECONOMICALLYVIABLE_API ACPlayerController : public APlayerController {
GENERATED_BODY()
public:
ACPlayerController();
virtual void BeginPlay() override;
virtual void SetupInputComponent() override;
UFUNCTION(Reliable, NetMulticast)
void MulticastRPCupdatePlayerState();
void MulticastRPCupdatePlayerState_Implementation();
};
CPlayerController.cpp
#include "EconomicallyViable.h"
#include "CPlayerController.h"
#include "GameStateC.h"
ACPlayerController::ACPlayerController() {
bAutoManageActiveCameraTarget = false;
}
void ACPlayerController::BeginPlay() {
Super::BeginPlay();
UKismetSystemLibrary::PrintString(this, TEXT("PC begin "), true, true, FLinearColor(1.000000, 1.000000, 1.000000, 1.000000), 40.0);
}
void ACPlayerController::SetupInputComponent() {
Super::SetupInputComponent();
InputComponent->BindAction("Jump", IE_Pressed, this, &ACPlayerController::MulticastRPCupdatePlayerState);
}
void ACPlayerController::MulticastRPCupdatePlayerState_Implementation() {
UKismetSystemLibrary::PrintString(this, TEXT("PC multicast "), true, true, FLinearColor(0.000000, 0.660000, 1.000000, 1.000000), 40.0);
}
What happens when I test it is unexpected.
When running 1 simulated client and 1 server in the editor:
Starts out with server calling BeginPlay twice and client calling once (as expected)
- Server: PC Begin
- Server: PC Begin
- Client 1: PC Begin
Pressing “Jump” on the server
causes the client to run BeginPlay on the playercontroller again.
Any key presses on the client are no longer registered.
The camera for the client is reset to character (seems bAutoManageActiveCameraTarget is back to true)
- Server: PC Multicast
- Client 1: PC Multicast
- Client 1: PC Begin
As you can see from the output the client is calling BeginPlay again resetting the playercontroller. Does anyone know what is causing this?