How to "ReplicatedUsing"

Thanks for the info, i knew that but couldnt get it to work. Finally after some tussle and bustle with codes… I have finally got it working!

To save others from the pain i had, here are the codes…


//  actor.h
	UFUNCTION()
	void LightTrigger();

	UFUNCTION(Server, Reliable, WithValidation)  
	void LightTriggerZ();
	void LightTriggerZ_Implementation();
	bool LightTriggerZ_Validate();

	UPROPERTY( ReplicatedUsing = LightTrigger)
	int32 WhatOn;




// actor.cpp
void AcLightSwitchCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> & OutLifetimeProps) const {
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(AcLightSwitchCharacter, WhatOn);
}

void  AcLightSwitchCharacter::PressButton() { 
	LightTriggerZ();
}

bool AcLightSwitchCharacter::LightTriggerZ_Validate() { return true; }

void AcLightSwitchCharacter::LightTriggerZ_Implementation() {
	WhatOn += 1;
	if (Role == ROLE_Authority)
		LightTrigger();
}

void AcLightSwitchCharacter::LightTrigger() {
	if (currentBox) {
		currentBox->toggleLight();
	}
}

4 Likes