Function Replication

I have a function to change some variables but I am unsure what is the proper method for replicating the Setting of this variable. Any help with this is greatly appreciated 's what I have and which is not working.

.h



UPROPERTY(UPROPERTY(BlueprintReadWrite, ReplicatedUsing = OnRep_IntVariable)
int32 IntVariable;

UFUNCTION()
void OnRep_IntVariable();

UFUNCTION(reliable, NetMulticast)
void SetIntVariable()

.cpp



void AClass::SetIntVariable_Implementation()
{
  if(Role == ROLE_Authority)//this does not resolve to true
  {
      IntVariable = 10;
  }
}

void AClass::OnRep_IntVariable()
{
//displayfunction  which is working
}

void AClass::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(AClass, IntVariable);
}


Hi DJMidKnight,

A ‘NetMulticast’ function runs on the server (if called on the server), and then out to all clients. Role will only equal ROLE_Authority on the server (for the most part).

Because of this, almost all of the calls to this function will result in your condition being false.

Also


int32 IntVariable;

is not replicated.
you need to use the macro UPROPERTY()

e.g:


UPROPERTY(Replicated)
     int32 IntVariable;

And then add the method


void GetLifetimeReplicatedPropsGetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const

And use the


DOREPLIFETIME(ACassName, IntVariable);

please excuse any typos or small errors in the naming, i dont have the code in front of me.
.

So what would be the proper replication to use? I prototyped this in a blueprint and am now moving it over to code. The blueprint works fine and where I had a Switch On Authority when I looked up what it was doing it went back to a bool in the Actorclass called HasAuthority which just returned Role == ROLE_Authority. So I tried to stay accurate to what worked. And I used multicast in the custom event which went thru the switch to the rest of the function.
Also what is strange is I can get the variable to increase and interact and increase again but if I try to decrease the value it works fine but on the next increase the decrease appears to have never happened. If it will help I will post a screenshot of the blueprint and try to put up a video.

Yes I have those in there for some reason I forgot to add them in when I wrote the post. The post has been updated with the accurate code.

If you are trying to change the value on the client, then you need to add a function to do that. Usually, it’ll be named ServerSetIntValue() and decorated with UFUNCTION(Reliable, Server). When the client calls that function, the value is sent to the server and executed there. Once modified by the server, the property replication will flow back to the client.



UFUNCTION(Reliable, Server)
void ServerSetIntValue(int32 NewValue);


thanks that was the basic direction I needed to head down and resolved the problem.