You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Character and Weapon classes in my project.
Weapon keeps its stats, such as MagazineAmmoCount on an attributeset that it owns. My "shoot" ability costs "1 MagazineAmmoCount" attribute to shoot. However, because these attributes are not initialized properly and instead I add them through SpawnedAttributes.AddUnique (as shown in this documentation), system crashes somewhere and my project closes.
Crash tells me that faulty line is following UFUNCTION() void OnRep_MagazineAmmoCount() { GAMEPLAYATTRIBUTE_REPNOTIFY(UZWeaponAttributeSet, MagazineAmmoCount); }
I have come up with following solution to work around this problem: AbilitySystem->InitStats(UZWeaponAttributeSet::StaticClass(), Weapon->StatInitializer); Weapon->InitializeAttributesFromThis(AbilitySystem);
Idea is to basically initialize attributes as standard, and then updating them manually using attribute set located at weapon. I havent tested the unequip function yet.
The text was updated successfully, but these errors were encountered:
I've actually concluded that using separate AttributeSets on weapons is not a great idea. The main issues are that changes to an Attribute from a GE must go through an ASC and we can't target a specific AttributeSet if more than one of the same class exists on the ASC or the AttributeSet is removed from the ASC but still valid in the world. This causes:
Complications with multiple weapons in your inventory.
If you remove an AttributeSet before an Attribute aggregator change is replicated, the replicated change will not find its AttributeSet and crash the game. I ran into this with a rocket launcher killing myself and removing the AttributeSet on Unequip/Death before the ammo change replication came in.
There are probably ways around these issues, but I find it was much easier just to use replicated raw floats on the weapons for magazine ammo with an Ammo AttributeSet on the Character for reserve ammo (this allows weapons to share reserve ammo of the same ammo type). I'm led to believe that Fortnite also does its ammo this way with raw floats on the weapons (I'm unsure about their reserve ammo).
My next sample project coming soon is an advanced FPS that shows this functionality and how to work with it in GameplayAbilities. I'll update the README when its released.
I have a Character and Weapon classes in my project.
Weapon keeps its stats, such as MagazineAmmoCount on an attributeset that it owns. My "shoot" ability costs "1 MagazineAmmoCount" attribute to shoot. However, because these attributes are not initialized properly and instead I add them through SpawnedAttributes.AddUnique (as shown in this documentation), system crashes somewhere and my project closes.
Crash tells me that faulty line is following
UFUNCTION() void OnRep_MagazineAmmoCount() { GAMEPLAYATTRIBUTE_REPNOTIFY(UZWeaponAttributeSet, MagazineAmmoCount); }
I have come up with following solution to work around this problem:
AbilitySystem->InitStats(UZWeaponAttributeSet::StaticClass(), Weapon->StatInitializer); Weapon->InitializeAttributesFromThis(AbilitySystem);
Idea is to basically initialize attributes as standard, and then updating them manually using attribute set located at weapon. I havent tested the unequip function yet.
The text was updated successfully, but these errors were encountered: