There’s this macro we’re supposed to use to change a property replication condition but where do you actually call this ? The macro seems to depend on OutLifetimeProps but so far the only function that have it is GetLifetimeReplicatedProps
Let’s say you start with
DOREPLIFETIME_CONDITION(ATestActor, RepData, COND_None);
and later I want to change to COND_OwnerOnly or something like that.
COND_xxx is an enum.
You can expose it as EditAnywhere property.
You should not try to change it at runtime.
Thanks for replying, I know COND_xx is an enum, I don’t need it exposed to BP but I do want to know how to change it at runtime.
I did some more digging and what I learned so far.
RESET_REPLIFETIME_CONDITION macro can be used to override the condition in a child class for example.
This quote from the 4.24 release.
New: Added RESET_REPLIFETIME macro that allows you to reenable a networked property that was disabled in a base class.
If want want to control the replication of a property I should use the PreReplication function and use this macro, this one can be done at runtime which is used in the shooter example and the actor class to replicate movement based on a condition.
So far I think it’s not possible to change from a certain condition to another specific condition at runtime though but DOREPLIFETIME_ACTIVE_OVERRIDE is close enough.
RESET_REPLIFETIME_CONDITION can do this.
#define RESET_REPLIFETIME_CONDITION(c,v,cond) ResetReplicatedLifetimeProperty(StaticClass(), c::StaticClass(), GET_MEMBER_NAME_CHECKED(c,v), cond, OutLifetimeProps);
and as mentioned abouse, needs to be done inside PreReplication function.
Here is a working example from my game, using the DOREPLIFETIME_ACTIVE_OVERRIDE but you can also change this to RESET_REPLIFETIME_CONDITION.
void AKaosWeapon_Ranged::PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker)
bool bCanReplicateAmmo = false;
if (UKaosAbilitySystemComponent* ASC = GetPawnASC())
bCanReplicateAmmo = !ASC->IsAbilityActive(PrimaryAbilitySpecHandle) && !ASC->IsAbilityActive(SecondaryAbilitySpecHandle);
DOREPLIFETIME_ACTIVE_OVERRIDE(AKaosWeapon_Ranged, AmmoCount, bCanReplicateAmmo || bUpdateLocalAmmoCount);
bUpdateLocalAmmoCount = false;
Thanks for replying.
Just to be sure, are you saying I can use RESET_REPLIFETIME_CONDITION in PreReplication, because I could not get that working. The RESET macro depends on OutLifetimeProps which can only be obtained in GetLifetimeReplicatedProps
I did some testing and your correct, it can only be done inside GetLifetimeReplicatedProps to override the base class’s replication condition. That is a shame.
I will do some additional tests, but i am not sure this is doable without engine modifications and the ramifications of doing so.
Will let you know my results.
Thank you for confirming, and I agree it’s probably not doable out of the box. If you find anything new please let me know.