I tried to set the value of a replicated variable of one actor from another actor.
The first actor is the owner of the second actor.
According to the documentation everything runs on the server side (I think).
Can’t the owned actor to modify its owner’s variables?
Or… What am I doing wrong?
Here is a code summary:
I can do GameMode function calls from the client side using the owned actor as a middleman. But I can’t modify owner variables.
//------------------------------------
//
//------------------------------------
UCLASS()
class ATheActor : public AInfo
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
public:
UFUNCTION(Server,Unreliable)
void DoSomethingOnServerSide(); //It does work
UFUNCTION(Server,Unreliable) //It does not work
void SetOwnerProperty(MyPlayerController *Owner);
};
void ATheActor::DoSomethingOnServerSide_Implementation()
{
Cast<AMyGameMode>(GetWorld()->GetAuthGameMode())->DoSomething(); //It does work
}
void ATheActor::SetOwnerProperty_Implementation(MyPlayerController *Owner)
{
Owner->SetIsDone(true); //It does not work
Cast<MyPlayerController>(GetOwner())->SetIsDone(true); //It does not work
}
//------------------------------------
//
//------------------------------------
UCLASS()
class AMyPlayerController : public APlayerController
{
GENERATED_BODY()
UPROPERTY(Replicated)
ATheActor *TheActor;
UPROPERTY(Replicated)
bool IsDone=false;
public:
virtual void BeginPlay() override;
UFUNCTION(Server,Unreliable)
void SetIsDone(bool Value);
UFUNCTION(Client,Unreliable)
void DoSomethingOnClientSide();
};
void AMyPlayerController::BeginPlay()
{
Super::BeginPlay();
if (!HasAuthority())return;
UWorld* World = GetWorld();
TheActor = World->SpawnActor<ATheActor>();
TheActor->SetOwner(this);
SetIsDone(true) //It does work
}
void AMyPlayerController::SetIsDone_Implementation(bool Value)
{
IsDone = Value;
}
void AMyPlayerController::DoSomethingOnClientSide_Implementation()
{
//It does work
TheActor->DoSomethingOnServerSide();
//It does not work
TheActor->SetOwnerProperty(this);
}
//------------------------------------
//
//------------------------------------
I think you are mixing things up too much. I’ve dived only a bit into the networking but I know this:
The server replicates down to clients, not the other way around.
Anything created by a client stays client side, does not end up on the server (think of spawns, or client only data like widgets).
The GameMode only lives on the server, as it should be. It’s not a place to store things, it’s a place to set up game rules / logic such as when a match starts / ends, or what score to give when a rule is met.
Yes, I know that variables can only be replicated from the server side.
But the actor (TheActor) allows me to communicate with the server from the client side (That works fine). It was spawned in the server world, replicated, and belongs to the PlayerContoller on the server side as well. That way the client side can have access to the GameMode (100% verified).
However, although it runs in the world context of the server, it is unable to replicate properties, neither its own nor those of its owner. (That’s what I don’t understand).
Or maybe this last paragraph is not correct…
Thank you very much for the link. I’m going to read it.