ReplicatedUsing function never gets called

Hello everyone!

Today i was trying to execute a function on variable value change,but UE doesn’t execute the function,what am i doing wrong?

my .h :

 UFUNCTION()
 void testrepfunc();
    
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category = "TESTCATEGORY", ReplicatedUsing = testrepfunc)
    		int32 testint = 0;

my .cpp :

void MyCharacter::testrepfunc()
{
	GEngine->AddOnScreenDebugMessage(-1, 20.0f,FColor::Orange, "Test");
}

void MyCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
   // do i need to insert something here?
}

Blueprint variable change (triggerbox)

You indeed need to add

Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(MyCharacter, testint);

Hey,Thanks for your answer!

I Modified the function like this :

void MyCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(MyCharacter, testint);
}

but still, the testrepfunc() doesn’t get called whenever testint changes value.

Got any idea?
Please let me know! :slight_smile:

You need to check whether this function is called on Server or on Client.
If you want the server to call that function, you have to do so manually.
Please check this thread that is very helpful.