Can a replicated property of an actor's owner be modified?

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); 
	
}

//------------------------------------
//
//------------------------------------

Thank you so much!!

The actor does not replicate to anything.
Neither do its own variables.

And yes, I have configured it as I normally would with any other replicated actor.

ATheActor::TheActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{	
	bReplicates = true;
	bAlwaysRelevant = true;
	NetPriority = 3.0f;
	SetReplicatingMovement(false);
}
void ATheActor::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > &OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(ATheActor, IsDone);

}

Replication just doesn’t work.
I don’t understand anything…

The server side works but does not replicate variables. It only works for running RPC on the server.

I think my head is going to explode!!
This means the end of the world as I knew it !! XD
Ok I think I can live with it…

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.
1 Like

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.


This is what I’m talking about:


RPC invoked from a Client:

Actor Ownership Not Replicated NetMulticast Server Client
Owned by invoking Client Runs on invoking Client Runs on invoking Client Runs on Server Runs on invoking Client

This does work!!

DOREPLIFETIME_CONDITION(UMyPlayerController, Test, COND_OwnerOnly);

Thank you so much for the link!!! :heart:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.