Effect and Attribute networking

For background, I’m building an RTS. Think of it as a scaled down version of Warcraft 3 or Starcraft. Each unit has an AI Controller.

I had some code where an attack animation sent a notification. My animation blueprint received that, grabbed a target from the blackboard, and then kicked off a damage effect. The damage effect was supposed to reduce the health of the target. Pulling from Blackboard meant the effect was only applied on the server, since blackboard doesn’t exist on client. I thought that was fine since the health value should replicate. It wasn’t.

Then, after reading GASDocumentation/Source/GASDocumentation/Public/Characters/Abilities/AttributeSets/GDAttributeSetBase.h at master · tranek/GASDocumentation · GitHub, I noticed there were OnRep values. So I’ve added the OnRep methods for health and max health. I also addeed the GetLifetimeReplicatedProps method.

I’m not sure if it’s replicating, but the weird thing is now the attributes aren’t initializing. I set the Default Starting Data in the AbilitySystemComponent to a data table. Once I added the OnRep methods, it appears to no longer initialize the values. They’re all set to 0.

I’ve initialized it like this:
image

  1. Should the effect run on the client? Or just server? Is there a way to replicate the effects over? Should I explictly set Replication mode to full? I haven’t explicitly set it myself, but I think the default is mixed. If I let it only run on the server, should I use the attribute replication for damage and fire off some cues for visuals?

  2. Is enabling replication somehow blocking or breaking use of Default Starting Data? Or should that still work?

class RTS_API UBaseUnitAttributeSet : public UAttributeSet
{
	GENERATED_BODY()

	UFUNCTION()
	virtual void OnRep_Health(const FGameplayAttributeData& OldHealth);

	UFUNCTION()
	virtual void OnRep_HealthMax(const FGameplayAttributeData& OldMaxHealth);

	

public:
	UPROPERTY(BlueprintReadOnly, Category = "Attributes", ReplicatedUsing = OnRep_Health)
	FGameplayAttributeData Health;
	ATTRIBUTE_ACCESSORS(UBaseUnitAttributeSet, Health);

	UPROPERTY(BlueprintReadOnly, Category = "Attributes", ReplicatedUsing = OnRep_HealthMax)
	FGameplayAttributeData HealthMax;
	ATTRIBUTE_ACCESSORS(UBaseUnitAttributeSet, HealthMax);
	
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;


};
void UBaseUnitAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth)
{
	GAMEPLAYATTRIBUTE_REPNOTIFY(UBaseUnitAttributeSet, Health, OldHealth);
}

void UBaseUnitAttributeSet::OnRep_HealthMax(const FGameplayAttributeData& OldHealthMax)
{
	GAMEPLAYATTRIBUTE_REPNOTIFY(UBaseUnitAttributeSet, HealthMax, OldHealthMax);
}

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

	DOREPLIFETIME_CONDITION_NOTIFY(UBaseUnitAttributeSet, Health, COND_None, REPNOTIFY_Always);
	DOREPLIFETIME_CONDITION_NOTIFY(UBaseUnitAttributeSet, HealthMax, COND_None, REPNOTIFY_Always);
}